Python:有没有办法从列表中获取多个项目?

Python:有没有办法从列表中获取多个项目?,python,dictionary,Python,Dictionary,我有一张有两本字典的单子。获取test.py和test2.py并将其作为列表[test.py,test2.py]的最简单方法是什么?如果可能的话,我想在没有for循环的情况下这样做 [ {'file': 'test.py', 'revs': [181449, 181447]}, {'file': 'test2.py', 'revs': [4321, 1234]} ] 可以使用列表comp-我想这是一种for循环: >>> d = [ {'file': 'test.py

我有一张有两本字典的单子。获取test.py和test2.py并将其作为列表[test.py,test2.py]的最简单方法是什么?如果可能的话,我想在没有for循环的情况下这样做

[  {'file': 'test.py', 'revs': [181449, 181447]}, 
{'file': 'test2.py', 'revs': [4321, 1234]}  ]
可以使用列表comp-我想这是一种for循环:

>>> d = [  {'file': 'test.py', 'revs': [181449, 181447]}, 
{'file': 'test2.py', 'revs': [4321, 1234]}  ]
>>> [el['file'] for el in d]
['test.py', 'test2.py']
如果不使用for这个词,您可以使用:

>>> from operator import itemgetter
>>> map(itemgetter('file'), d)
['test.py', 'test2.py']
或者,在没有导入的情况下:

>>> map(lambda L: L['file'], d)
['test.py', 'test2.py']
可以使用列表comp-我想这是一种for循环:

>>> d = [  {'file': 'test.py', 'revs': [181449, 181447]}, 
{'file': 'test2.py', 'revs': [4321, 1234]}  ]
>>> [el['file'] for el in d]
['test.py', 'test2.py']
如果不使用for这个词,您可以使用:

>>> from operator import itemgetter
>>> map(itemgetter('file'), d)
['test.py', 'test2.py']
或者,在没有导入的情况下:

>>> map(lambda L: L['file'], d)
['test.py', 'test2.py']

这就是我要找的。谢谢。不过,Map实际上只是说明for循环的另一种方式。列表理解是一种方法。@JeffFerland是真的-但它不是Python级别的for循环;这就是我要找的。谢谢。不过,Map实际上只是说明for循环的另一种方式。列表理解是一种方法。@JeffFerland是真的-但它不是Python级别的for循环;