Extracting values of elements in a list of dictionaries

后端 未结 5 729
甜味超标
甜味超标 2021-01-29 11:46

I have a python data-structure as follows:

A = [{\'abc\': \'kjkjl\'},{\'abc\': \'hjhjh\'},{\'abc\': \'78787\'}]

How can I remove the \'abc\' fr

5条回答
  •  春和景丽
    2021-01-29 12:30

    If all the dicts in A only have one element, you can do this ...

    >>> A = [{'abc': 'kjkjl'},{'abc': 'hjhjh'},{'abc': '78787'}]
    >>> B = [x.values()[0] for x in A]
    >>> B
    ['kjkjl', 'hjhjh', '78787']
    

提交回复
热议问题