python List嵌套dict获取所有属性的value值
list_a=[{'name': '张三', 'age':18}, {'name': '李四', 'age': 19}, {'name': '王五', 'age':18}, {'name': '李四', 'age': 19}]
key = [item[key] for item in list_a for key in item]
print ("===>>>key:" ,key)
输出结果:===>>>key: ['张三', 18, '李四', 19, '王五', 18, '李四', 19]
python List嵌套dict获取某个属性的value值
list_a = [{'name': '张三', 'age':18}, {'name': '李四', 'age': 19}, {'name': '王五', 'age':18}, {'name': '李四', 'age': 19}]
list_b = []
for item in list_a:
list_b.append(item['name'])
print ("===>>>key:" ,list_b)
输出结果:===>>>key: ['张三', '李四', '王五', '李四']