In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article introduces the knowledge about "what Python code is written". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!
Print index
For a list, or a sequence, we often need to print its index, which is generally traditional or relatively low:
A more elegant way to write this is to enumerate.
Cycle of two sequences
We will often compute or process two sequences, and the way to compare low is to use subscripts to cycle.
A more elegant way: zip it easily
Is there a more elegant way, for example, if two sequences have a length of 10000, of course, some use izip
Of course izip is still a product of Py2.x era, and now Py3.6 default zip is izip!
exchange variables
Exchange between multiple variables, I believe many students with c,c++ language foundation are familiar with this, such as our classic bubble sort, will use this trick, look at the more traditional approach:
A more elegant approach would be:
dictionary reading
Dictionary is a data structure we often use. For dictionary access and reading, what if the dictionary key we read is empty? Generally, we need a default value.
The more elegant approach is:
If there is no Susan key in the dictionary, use unknow to express the default value!
circular search
We often do search operations in a large loop, such as searching for keywords in a file, such as looking up some special file name from a list of file names, which is written as follows:
More elegant writing: The above is the traditional c,c++ writing, Python has a more concise writing:
file read lookup
Generally speaking, we want to open a file, and then loop the contents of the file to read and process, rookie writing is as follows:
More elegant wording:
About lock writing
For concurrent operations, especially multithreaded operations, when we read and write to the same block of memory, we usually add lock protection. The assumed writing is as follows:
I wrote the above writing for many years myself, and I felt that there was no problem. Later, I encountered the following writing and instantly worshipped it!
More elegant wording:
"Python code writing what" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.