Hits: 203
資料操作筆記
紀錄一下自己有碰過的資料操作紀錄
list of dictionary to dictionry
想要將 list of dictionary 轉成單純的 dictionary,可透過 list comprehension + dict comprehension 達成
ld = [{'month': '10901',
'pat_id': 'A666666666',
'last_approve_begin_date': '20200906',
'last_approve_end_date': '20201205'}]
dict((key, val) for k in ld for key, val in k.items())
回傳下列結果
{'month': '10901',
'pat_idno': 'A666666666',
'last_approve_begin_date': '20200906',
'last_approve_end_date': '20201205'}
Comments