Getting a list of specific index items from a list of dictionaries in python (list comprehension)

后端 未结 5 1185
北海茫月
北海茫月 2021-01-24 08:31

I have a list of dictionaries like so:

listDict = [{\'id\':1,\'other\':2},{\'id\':3,\'other\':4},{\'id\':5,\'other\':6}]

I want a list of all t

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-24 08:48

    >>> listDict = [{'id':1,'other':2},{'id':3,'other':4},{'id':5,'other':6}]
    >>> [item["id"] for item in listDict]
    [1, 3, 5]
    

提交回复
热议问题