l = [
{'bob':'hello','jim':'thanks'},
{'bob':'world','jim':'for'},
{'bob':'hey','jim':'the'},
{'bob':'mundo','jim':'help'}
]
for dict in l:
print dict['jim']
In []: l
Out[]:
[{'bob': 'hello', 'jim': 'thanks'},
{'bob': 'world', 'jim': 'for'},
{'bob': 'hey', 'jim': 'the'},
{'bob': 'mundo', 'jim': 'help'},
{'bob': 'gratzie', 'jimmy': 'a lot'}]
In []: [d['jim'] for d in l if 'jim' in d]
Out[]: ['thanks', 'for', 'the', 'help']
当然,例如:
是的,功能编程良好:
并且不要使用
dict
作为变量名。它屏蔽了dict()
内置的。在相关问题 更多 >
编程相关推荐