Circular dictionary of Python knowledge points

loop dictionary

A dictionary is a key-value pair. Beginners may not be used to how to loop a dictionary:

Method 1: Cycle key

scores = {
    
    'zhangsan':98, 'lisi':89, 'maishu':96}

for name in scores:
  print(f'{name}:{scores[name]}')
  • By default, the loop dictionary is actually the keys of the loop dictionary, so the name is a key.
  • If you need to access the value, you can access it through scores[name ].

Results of the:

zhangsan:98
lisi:89
maishu:96
[Finished in 15ms]

Because the default cycle is keys, the following code is exactly the same principle as above:

for name in scores.keys():
  print(f'{name}:{scores[name]}')

We call the scores.keys() method to get a list of keys, and then loop over it. This is the same effect as above.

Method 2: Loop key and value

If you want to access key and value more conveniently, you can write like this:

for name, score in scores.items():
  print(f'{name}:{score}')

Through the items() function, the dictionary is converted into a list of ( key, value ) tuples, so that the key and value can be accessed directly.

In order to be more intuitive in the code, we use name and score to represent key and value.

Note that Python's automatic package opening function is also used here to automatically turn the tuple into two variables.

Method 3: Print the serial number

If you want to print the serial number in addition to the key and value. The desired result is something like this:

0 zhangsan 98
1 lisi 89
2 maishu 96

You can use the enumerate function, the code is as follows:

scores = {
    
    'zhangsan':98, 'lisi':89, 'maishu':96}

for i, (name, score) in enumerate(scores.items()):
   print(i, name, score)

First use the items() function to convert it into a list of tuples, and then use the enumerate function to add the serial number.

Note that because it is a tuple, parentheses must be added to the variable of for: i, (name, score ). Python can only do simple automatic package opening. There is also a variable i , which will not automatically open the package. It is just a single variable tuple and needs to be added with parentheses.

Career Development

As a code wage earner, for the vast majority of programmers, there is still a long way to go to become an awesome real money-making programmer, and they can't slack off for a moment.

We cannot guess which state of the interview is more favored by the interviewer from the perspective of HR or the technical leader. But through the large amount of interview experience we have accumulated, you can more or less infer some of the necessary conditions to become a competitive programmer.

Gathering of bigwigs and rich information

At the beginning, I met a very, very senior senior in Byte. He came to Byte three years earlier than me, but his level was not very high for various reasons. I asked him at the time, since you are so dissatisfied with the status quo, why don't you think about leaving to find better opportunities?

He pondered for a moment and told me that although my stay here is not going well, the people I have come into contact with are all excellent. I have a problem, and I can discuss it with you. If I go out, if I encounter problems again, there may not even be anyone to discuss.

I just thought it made sense when I heard it at the time, but looking back now, I feel very profound. Three outlooks, structure, ability, those who can enter a large company, these three aspects are generally not too bad. Among other things, as far as personal ability is concerned, I have traveled abroad for several months, and I have been fortunate enough to meet many colleagues from various famous overseas schools, and learn and communicate with them on artificial intelligence. This really gave me a deeper understanding of AI. know.

In addition to excellent colleagues, large companies often have rich internal documents and materials. At that time, I saw many excellent articles inside Byte, and there were also many excellent technical salons and sharing. Now that I think about it, I haven’t been there a few times in the past two years, and I haven’t read too many articles and materials. It’s a pity now that I think about it. Among other things, as far as the field of recommendation is concerned, the papers with good quality in recent years often come from large companies, especially large domestic companies, mainly Tencent, Huawei and Toutiao. In addition to the public papers, there are a lot of technology-related materials and documents within the company. These are really valuable and have no market, and are very precious.

Python Knowledge Manual

Linux Knowledge Manual

The crawler query manual

Moreover, these materials are not scanned versions, and the text inside can be copied directly, which is very convenient for us to learn:

Data Analysis Knowledge Manual:

Machine Learning Knowledge Handbook:

Handbook of Financial Quantitative Knowledge:

Job referral, learning exchange

We need a large number of front-end positions, python positions, Java positions, Android and iOS development positions, working location: Beijing Byte, welcome school recruiters to scan the QR code below to find me to recommend

Python information, technology, courses, answers, consultation can also directly click on the business card below,添加官方客服斯琪

Guess you like

Origin blog.csdn.net/JAVAmonster12/article/details/123260083