convert list of dicts to list

后端 未结 4 2034
有刺的猬
有刺的猬 2020-12-16 19:07

I have a list of fields in this form

fields = [{\'name\':\'count\', \'label\':\'Count\'},{\'name\':\'type\', \'label\':\'Type\'}]

I\'d like

4条回答
  •  [愿得一人]
    2020-12-16 19:48

    You can use a list comprehension:

    >>> fields = [{'name':'count', 'label':'Count'},{'name':'type', 'label':'Type'}]
    >>> [f['name'] for f in fields]
    ['count', 'type']
    

提交回复
热议问题