官术网_书友最值得收藏!

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']
主站蜘蛛池模板: 从化市| 二手房| 姜堰市| 凤庆县| 嘉兴市| 嘉禾县| 抚宁县| 莒南县| 沙河市| 芒康县| 邵武市| 遂宁市| 金秀| 原阳县| 曲松县| 苗栗县| 舞钢市| 威远县| 亚东县| 荣成市| 阿坝县| 唐海县| 玉龙| 曲松县| 五常市| 资阳市| 香港 | 江门市| 玉山县| 阿尔山市| 安图县| 巴林右旗| 蚌埠市| 张家港市| 东至县| 宜兰县| 江华| 阳泉市| 互助| 彝良县| 利川市|