- Mastering Python Networking
- Eric Chou
- 166字
- 2021-07-02 21:42:32
Mapping
Python provides one mapping type called dictionary. Dictionary is what I think of as a poor man's database, because it contains objects that can be indexed by keys. This is often referred to as the associated array or hashing table in other languages. If you have used any of the dictionary-like objects in other languages, you will know this is a powerful type, because you can refer to the object by a readable key. This key will make more sense for the poor guy who is trying to maintain the code, probably a few months after you wrote the code at 2 am in the morning. The object can also be another data type, such as a list. You can create a dictionary with curly braces:
>>> datacenter1 = {'spines': ['r1', 'r2', 'r3', 'r4']}
>>> datacenter1['leafs'] = ['l1', 'l2', 'l3', 'l4']
>>> datacenter1
{'leafs': ['l1', 'l2', 'l3', 'l4'], 'spines': ['r1',
'r2', 'r3', 'r4']}
>>> datacenter1['spines']
['r1', 'r2', 'r3', 'r4']
>>> datacenter1['leafs']
['l1', 'l2', 'l3', 'l4']
推薦閱讀
- 一步一步學(xué)Spring Boot 2:微服務(wù)項(xiàng)目實(shí)戰(zhàn)
- Kali Linux Web Penetration Testing Cookbook
- Beginning C++ Game Programming
- Python機(jī)器學(xué)習(xí):數(shù)據(jù)分析與評(píng)分卡建模(微課版)
- Silverlight魔幻銀燈
- JBoss:Developer's Guide
- Buildbox 2.x Game Development
- Mastering Apache Storm
- Clojure for Java Developers
- Learning Android Application Testing
- SQL Server 2012 數(shù)據(jù)庫(kù)應(yīng)用教程(第3版)
- 從零開(kāi)始學(xué)Python大數(shù)據(jù)與量化交易
- Neo4j 3.x入門經(jīng)典
- Keil Cx51 V7.0單片機(jī)高級(jí)語(yǔ)言編程與μVision2應(yīng)用實(shí)踐
- Android嵌入式系統(tǒng)程序開(kāi)發(fā)(基于Cortex-A8)