Collect it quickly so that you can use the 30 Python tips for taking off
2022-02-01 15:53:39 【aikutwo】
Python Is one of the most popular languages , Many people use it for data science and machine learning 、Web Development 、 scripting 、 Automation and other fields .
This popularity is partly due to its simplicity and ease of learning .
In this paper , I'll introduce you to 30 A short 、 Economic Python skill . The content is more , It is suggested to collect and study , Like to like and support
1. All unique
The following method checks whether a given list has duplicate elements , It USES set() Remove duplicate elements from the list with the properties of .
2. Crossword puzzle
This method can be used to check whether two strings are riddles . A word puzzle is a word or phrase formed by rearranging the letters of different words or phrases , Usually all original letters are used only once .
This code snippet can be used to check the memory usage of an object .
4. Byte size
This method uses Byte Returns the length of a string in units .
5. Print a string N Time
This code snippet can be used to print strings n Time , You don't need a loop to do this .
6. title case
This code snippet uses only title() Method capitalizes the first letter of each word in the string .
7. List cut
This method divides the list into smaller lists of the specified size .
8. Delete false values
This method uses filter() Remove false values from the list （False、None、0 and “”）
9. Transpose a two-dimensional array
This code snippet can be used to transpose a two-dimensional array
10. Chain comparison
You can compare various operators multiple times in a row .
11. Comma separated
This code snippet can be used to convert a list of strings to a single string , Each element in the list is separated by commas .
12. Get vowels
This method gets the vowels in the string （‘a’、‘e’、‘i’、‘o’、‘u’）
This method can be used to convert the first letter of a given string to lowercase .
The following method uses recursion to flatten potential deep lists .
This method finds the difference between two iterations by retaining only the value in the first one .
After applying the given function to each element of both lists , The following method returns the difference between two lists .
17. Chain function call
You can call multiple functions in one line.
18. duplicate value
The following methods are implemented by using set() The fact that it contains only unique elements , To check if the list has duplicate values .
19. Merge two dictionaries
The following methods can be used to merge two dictionaries
stay Python 3.5 And later , You can also do something like this ：
20. Convert two lists into dictionaries
The following methods can be used to convert two lists into dictionaries
21. Use enumeration
This code snippet shows that you can use enumerate To get the value and index of the list .
22. Time spent calculating
This code snippet can be used to calculate the time required to execute a particular code .
You can use else Clause as try/except Part of the block , If no exception is thrown , Will execute the block .
24. Statistics are most frequent
This method returns the most frequent element in the list .
This method checks whether the given string is a palindrome .
26. No, if-else 's calculator
The following code snippet shows how to use if-else Condition, write a simple calculator .
This code snippet can be used to randomize the order of elements in the list . Please note that ,shuffle Local work , And back to None.
28. List flatten
29. Exchange value
This is a very fast way to swap two variables without using additional variables .
30. Get the default value of the missing key
This code snippet shows how to get the default value if the dictionary does not contain the key you want to find .
More programming related knowledge recommended link Watch the instructional video ~
author[aikutwo],Please bring the original link to reprint, thank you.
The sidebar is recommended
- Python learning notes - the fifth bullet * class & object oriented
- Python learning notes - the fourth bullet IO operation
- Python crawler actual combat: crawl all the pictures in the answer
- Quick reference manual of common regular expressions, necessary for Python text processing
- [Python] the characteristics of dictionaries and collections and the hash table behind them
- Python crawler - fund information storage
- Python crawler actual combat, pyteseract module, python realizes the visualization of boos direct employment & hook post data
- Pit filling summary: Python memory leak troubleshooting tips
- Python code reading (Chapter 61): delaying function calls
- Through the for loop, compare the differences between Python and Ruby Programming ideas
guess what you like
leetcode 1606. Find Servers That Handled Most Number of Requests（python）
leetcode 1611. Minimum One Bit Operations to Make Integers Zero（python）
06python learning notes - reading external text data
[Python] functions, higher-order functions, anonymous functions and function attributes
Python Networkx practice social network visualization
Data analysis starts from scratch, and pandas reads and writes CSV data
Python review (format string)
[pandas learning notes 01] powerful tool set for analyzing structured data
leetcode 147. Insertion Sort List（python）
apache2. 4 + windows deployment Django (multi site)
- Python data analysis - linear regression selection fund
- How to make a python SDK and upload and download private servers
- Python from 0 to 1 (day 20) - basic concepts of Python dictionary
- Django -- closure decorator regular expression
- Implementation of home page and back end of Vue + Django tourism network project
- Easy to use scaffold in Python
- [Python actual combat sharing] I wrote a GIF generation tool, which is really TM simple (Douluo continent, did you see it?)
- [Python] function decorators and common decorators
- Explain the python streamlit framework in detail, which is used to build a beautiful data visualization web app, and practice making a garbage classification app
- Construction of the first Django project
- Python crawler actual combat, pyecharts module, python realizes the visualization of river review data
- Python series -- web crawler
- Plotly + pandas + sklearn: shoot the first shot of kaggle
- How to learn Python systematically?
- Analysis on several implementations of Python crawler data De duplication
- leetcode 1616. Split Two Strings to Make Palindrome （python）
- Python Matplotlib drawing violin diagram
- Python crawls a large number of beautiful pictures with 10 lines of code
- [tool] integrated use of firebase push function in Python project
- How to use Python to statistically analyze access logs?
- How IOS developers learn Python Programming 22 - Supplement 1
- Python can meet any API you need
- Python 3 process control statement
- The 20th of 120 Python crawlers, 1637. All the way business opportunity network joined in data collection
- Datetime of pandas time series preamble
- How to send payslips in Python
- [Python] closure and scope
- Application of Python Matplotlib color
- leetcode 1627. Graph Connectivity With Threshold （python）
- Python thread 08 uses queues to transform the transfer scenario
- Python: simple single player strange game (text)
- Daily python, chapter 27, Django template
- TCP / UDP communication based on Python socket
- Use of pandas timestamp index
- leetcode 148. Sort List（python）
- Confucius old book network data collection, take one anti three learning crawler, python crawler 120 cases, the 21st case
- [HTB] cap (datagram analysis, setuid capability: Python)
- How IOS developers learn Python Programming 23 - Supplement 2
- How to automatically identify n + 1 queries in Django applications (2)?
- Data analysis starts from scratch. Pandas reads HTML pages + data processing and analysis