python 字典列表 列表字典

如何访问字典列表,列表字典中的元素?

 

字典列表:一个列表,其元素是字典
获取'65':列表settings中的字典{'default_value': '65', 'name': 'storage_group_near_full_threshold'}中的值
>>> settings=[{'default_value': '65', 'name': 'storage_group_near_full_threshold'}, {'default_value': '85', 'name': 'storage_group_full_threshold'}, {'default_value': '75', 'name': 'ceph_near_full_threshold'}, {'default_value': '90', 'name': 'ceph_full_threshold'}, {'default_value': '100', 'name': 'pg_count_factor'}]
>>> for i in settings:
...     if i['name']=='storage_group_near_full_threshold':
...             print i['default_value']
...
65

列表字典:一个字典,其键值有列表
获取'65':字典settings中的列表['65', '85', '75', '90', '100']中的值
>>> settings={'name': 'settings', 'third': [], 'second': ['65', '85', '75', '90', '100'], 'single': [], 'fourth': [], 'fifth': [], 'first': ['storage_group_near_full_threshold', 'storage_group_full_threshold', 'ceph_near_full_threshold', 'ceph_full_threshold', 'pg_count_factor']}
>>> print settings['first'].index('storage_group_near_full_threshold')
0
>>> index=settings['first'].index('storage_group_near_full_threshold')
>>> print settings['second'][index]
65
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值