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

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']
主站蜘蛛池模板: 大埔区| 三门峡市| 五指山市| 新营市| 岑溪市| 乌海市| 喜德县| 浙江省| 彰化市| 田阳县| 科技| 茂名市| 文水县| 木兰县| 鹿邑县| 旺苍县| 永年县| 利津县| 湟中县| 东莞市| 庆城县| 德令哈市| 虎林市| 县级市| 阜城县| 灌南县| 东乡县| 淮北市| 石台县| 阜新市| 板桥市| 丹巴县| 仙游县| 镇坪县| 高雄市| 綦江县| 华容县| 莲花县| 基隆市| 长宁区| 靖边县|