Current location - Recipe Complete Network - Complete cookbook of home-style dishes - 10 minimalist python code, ready to use.
10 minimalist python code, ready to use.
Hello, I'm Wang Xiaocheng ~

Although python is a simple and easy-to-learn language, many people still ask how to learn Python the fastest. The answer, of course, is to practice various small projects. Only by thinking and writing by yourself can you remember the rules. This article is about 10 minimalist task, and beginners can try to finish it by themselves. This article is also 10 code, and Python developers can also see if there are any unexpected uses.

The following method can check whether there are duplicate elements in a given list, and it will use the set () function to delete all duplicate elements.

Given a specific size, define a function to cut the list according to this size.

This method can delete Boolean values, such as (False, None, 0, ""), and it uses the filter () function.

We often use the For loop to traverse a list, and we can also enumerate the indexes and values of the list.

The following code snippet can unpack the packed paired list into two different tuples.

This method recursively extends the nesting of lists into a list.

This method returns the elements in the first list, which are not in the second list. If you want to feed back the unique element of the second list at the same time, you need to add a set_b.difference(set_a).

The following code blocks can be used to calculate the time required to execute a specific code.

This algorithm will disturb the order of list elements, and mainly sort the new list by Fisher-Yates algorithm:

You can exchange the values of two variables without additional operations.

Above, I simply listed ten python minimalist codes, hoping to help you!