Thursday, May 21, 2020

What can a single line of Python code do?

Python has a lot of elegant and interesting code writing, and it is also very short, so that when I first started to contact this programming language, I couldn't put it down. In the list of programming languages a few days ago, python also surpassed java and became the first, quite happy for python.

How interesting is Python? One line of code tells you!

1) Draw love

print(' '.join([''.join([('sergiojune'[(x-y)%10]if((x*0.05)**2+(y*0.1)**2-1)**3-(x*0.05)**2*(y*0.1)**3<=0 else' ')for x in range(-30,30)])for y in range(15,-15,-1)]))

This can be described as a confession artifact. You can show it off every holiday, brother dei, understand me?

2) Draw a Mandelbrot
print(' '.join([''.join(['*'if abs((lambda a:lambda z,c,n:a(a,z,c,n))(lambda s,z,c,n:z if n==0else s(s,z*z+c,c,n-1))(0,0.02*x+0.05j*y,40))<2 else' 'for x in range(-80,20)])for y in range(-20,20)]))

3) Print 99 multiplication table
print(' '.join([' '.join(['%s*%s=%-2s' % (y, x, x*y) for y in range(1, x+1)]) for x in range(1, 10)]))

4) One line of code for quick sorting
qs = lambda xs : ( (len(xs) <= 1 and [xs]) or [ qs( [x for x in xs[1:] if x < xs[0]] ) + [xs[0]] + qs( [x for x in xs[1:] if x >= xs[0]] ) ] )[0]

5) Two variables can be exchanged
a, b = b, a

This should be simple. Also pythonic style.

6) Print the Zen of python
import this

Many people do not know this estimate. You often say "life is short, I use python". The beauty of python is often reflected in it. Good Python programmers should also follow it.

7) Watch comics
import antigravity

Wednesday, May 20, 2020

5 cool Python tools

If you want to do your best, you must first sharpen your tool. A good tool can do more with less. The Python community provides enough excellent tools to help developers implement some ideas more conveniently. My work also brings a lot of convenience, recommended to you who pursue beautiful things.

Python Tutor

Python Tutor is a free educational tool developed by Philip Guo that can help students overcome the basic obstacles in programming learning and understand the process of each line of source code in the computer when the program is executed. With this tool, teachers or students can write Python code directly in a Web browser and gradually run the program visually. If you don't know how the code runs in memory, you may wish to copy it to Tutor for visual execution and deepen your understanding.



IPython is a Python interactive shell for Humans. After using it, you do n’t want to use the built-in Python shell anymore. IPython supports variable completion, automatic indentation, bash shell commands, and many built-in functions and functions. It is also the best platform for scientific computing and interactive visualization. Reply to "ipython" for "IPython Interactive Programming and Data Visualization Tutorial".

Jupyter Notebook

Jupyter Notebook is like a draft book, which can combine text annotations, mathematical equations, code and visual content into an easy-to-share document and display it as a Web page. It is an essential tool for data analysis and machine learning. Reply "jupyter" to show you a Python tutorial based on jupyter.



Although Python is good, you can always encounter various package management and Python version problems, especially on the Windows platform, many packages cannot be installed normally. In order to solve these problems, Anoconda has appeared. Anoconda includes a package management tool and a Python management environment At the same time, a large number of commonly used data science packages are also included, which is also standard for data analysis. I have introduced Anaconda in the public account before


Skulpt is an online Python execution environment implemented in Javascript, which allows you to easily run Python code in a browser. Using skulpt combined with CodeMirror editor can realize a basic online Python editing and running environment.