convert list of dicts to list

后端 未结 4 2035
有刺的猬
有刺的猬 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 20:01

    names = [x['name'] for x in fields] would do.

    and if the list names already exists then:

    names += [x['name'] for x in fields]
    

提交回复
热议问题