- 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']
推薦閱讀
- 數據庫系統教程(第2版)
- PostgreSQL技術內幕:事務處理深度探索
- SAS數據統計分析與編程實踐
- Mastering JBoss Enterprise Application Platform 7
- Hands-On Full Stack Development with Go
- .NET 3.5編程
- 低代碼平臺開發實踐:基于React
- MySQL入門很輕松(微課超值版)
- Spring Security Essentials
- Kubernetes進階實戰
- 愛上C語言:C KISS
- Practical GIS
- 青少年學Python(第2冊)
- iOS開發項目化入門教程
- After Effects CC案例設計與經典插件(視頻教學版)