- 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']
推薦閱讀
- Implementing VMware Horizon 7(Second Edition)
- 手機安全和可信應用開發指南:TrustZone與OP-TEE技術詳解
- Spring Cloud Alibaba核心技術與實戰案例
- 微服務與事件驅動架構
- 匯編語言程序設計(第2版)
- Mastering Kali Linux for Web Penetration Testing
- Troubleshooting PostgreSQL
- Go并發編程實戰
- INSTANT Passbook App Development for iOS How-to
- UML 基礎與 Rose 建模案例(第3版)
- PHP從入門到精通(第4版)(軟件開發視頻大講堂)
- 從零開始學Linux編程
- Azure Serverless Computing Cookbook
- 實戰Java高并發程序設計(第2版)
- OpenCV 3 Blueprints