May 29, 2021 Article blog
1. One, half a paragraph of a list of values are all less than a certain number
2. Second, the string of the list is sorted according to specific requirements
3. Third, sort the dictionary by key or numeric value
4. Fourth, replace the number of the list with a string
5. Whether the five- and half-segment list elements are all of a type
7. Seven, from the iterative object randomly selected an element
8. Eight, use the list to create a dictionary
9. Nine, filter out the string that begins with the vowel letter
For Python learners, mastering the simple and efficient programming skills in Python improves program efficiency and draws on the programmer's superior programming skills.
This article introduces ten small cases of Python, each with two workarounds. The first is relative to Xiaobai's writing, and the second is the experienced master's writing.
Method 1: The most intuitive program is one to determine whether the elements in the list are less than a certain number, such a method is the easiest to think of, but the program is very complicated.
Method 2: Two Python built-in functions, Python anonymous functions, can be easily solved with one line of code.
Method 1: Is to use the bubbling sort to solve;
Method 2: Just use the built-in function sorted one line of code to solve the problem. Not only that, but you can also set up your own sorting functions, such as the firstC function above, to sort by the first letter of the string for the specified aspects of the sorted keywords.
Method 1: You can sort with the sorted built-in function and convert it to a dictionary. Such a way would result in a waste of space resources during the conversion process.
Method 2: It is directly using the key or value to sort, and then use the sorted key or value to construct the final dictionary, and the program is simple.
Method 1: Take advantage of the list resolution scenario to generate new lists by iteratively.
Method 2:
Use the map built-in function to convert the numbers in the list to strings.
Method 1:
The method used is to create a new list object and add the elements in list6 to the new list in a backward-forward manner.
By selecting random values in Python, we can take advantage of Python's built-in library random, in the figure function above,
the choice
function randomly selects a number from the list,
the choices
function puts back the select k value, and
sample
is the select k value without playback.
Method 1: Create a dictionary with a list, and create a item of key-value pairs in the dictionary by looping for.
Method 2: Create a zip object with the zip built-in function, and use the dict function to convert the zip object into a dictionary, one line of code.
Method 1: For each string element in list9, if the first letter of the string is the cause letter, add the string to the new list new_list9.
Method 2: The filter function can directly filter out the value of the element that meets the criteria compared to the map function, either directly using list resolution or filtering elements in list9 that meet the criteria.
That's all you need to know about the Python rookie practice program.