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

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']
主站蜘蛛池模板: 奎屯市| 什邡市| 阿瓦提县| 罗平县| 元阳县| 乌兰浩特市| 呼伦贝尔市| 江华| 玉林市| 互助| 佛山市| 大连市| 沅陵县| 银川市| 太和县| 江北区| 利川市| 江口县| 庄浪县| 互助| 宝鸡市| 镇沅| 陵水| 吉木乃县| 化隆| 离岛区| 承德市| 新乡县| 桑植县| 罗源县| 资兴市| 大足县| 临高县| 胶州市| 榆社县| 永顺县| 阿尔山市| 临洮县| 勃利县| 鸡泽县| 垫江县|