iT邦幫忙

1

python list to dict

大家好:
https://ithelp.ithome.com.tw/upload/images/20190819/20116986gg9wTl4Wvy.png這是我的資料(list),想問要怎把他整個轉成dict的格式,網路上的一些方法皆會碰到錯誤(unhashable type: 'dict' 或 'dict' object has no attribute 'split' )

圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

1 個回答

1
dragonH
iT邦超人 5 級 ‧ 2019-08-19 16:03:57
最佳解答

ideone

myLists = [
  {'1': '123', '2': '456', '3': '789'},
  {'1': '999', '2': '888'},
  {'1': '987', '2': '888', '3': '777', '4': '666'},
]

myDict = dict(enumerate(myLists, start=1))

print(type(myDict))
print(myDict)
print(myDict[1])

這樣嗎?

對~太感謝惹~

我要發表回答

立即登入回答