Three levels of python learning notes,

Source: Internet
Author: User

Three levels of python learning notes,

1. Correct Dictionary (others') 2 zone = {3 'North China': {'shandong ': {'qingdao': ['sifang '] ,},}, 4 'south': {'jiangsu ': {'suzhou': ['canglang '] ,},}, 5} 6 is not an error, but an unreasonable Dictionary (mine) 7 dic_china = {8 "Municipalities": {"Beijing": ["Dongcheng District",] ,}, 9 "Province": {"Zhejiang Province": {"Hangzhou City ": ["gongshu district",], },} 10}

Comparing the two dictionaries, it is not difficult to find that the dictionary I created actually belongs to the second-level dictionary rather than the third-level dictionary.

Misunderstanding:

I think the level of the dictionary is determined by the "long wooden board", that is, the dictionary "china" ---> Dictionary "Province" ---> Dictionary "Zhejiang Province ", in fact, it is determined by the "short board", that is, the dictionary "china" ---> the dictionary "municipality ",

Final result:

Code: dic_china ['province '] ['zhejiang province']. keys (): Yes. An error is returned when the code is executed: Unresolved attribute reference 'key' for class

Code: zone ['North China'] ['shandong ']. keys (): Correct. The output value is Qingdao.

 

Ps: I tried again and found that dic_china ['province '] ['zhejiang province'] was directly output. The output result is Hangzhou city, that is: I originally guessed {"Hangzhou City ": ["gongshu district",],} The conjecture that python recognizes as a value seems to be wrong. I really don't understand it. I still need to continue learning the dictionary, I don't know if there are any technical experts who can solve this problem ??

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.