Extracting values of elements in a list of dictionaries

后端 未结 5 713
甜味超标
甜味超标 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:10

    Given your list as

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

    You can do something like

    >>> list(itertools.chain(*[x.values() for x in A]))
    ['kjkjl', 'hjhjh', '78787']
    >>> 
    

提交回复
热议问题