Extract all keys from a list of dictionaries

前端 未结 6 770
遇见更好的自我
遇见更好的自我 2020-12-08 03:58

I\'m trying to get a list of all keys in a list of dictionaries in order to fill out the fieldnames argument for csv.DictWriter.

previously, I had something like thi

6条回答
  •  自闭症患者
    2020-12-08 04:39

    all_keys = set().union(*(d.keys() for d in mylist))
    

    Edit: have to unpack the list. Now fixed.

提交回复
热议问题