有很多例子如何转换一个简单的嵌套列表做字典,但我如何迭代这样的数据结构
bookings = [['3473', '2021-04-22 14:00'], ['3633', '2021-04-20 15:00'], ['3633', '2021-04-21 11:00']]
为此:
obj = {
'Date': '2021-04-22 14:00',
'ID': '3473'
}
答案 0 :(得分:1)
您可以遍历列表并制作字典。
for e in bookings:
obj = dict()
obj['id'] = e[0]
obj['date'] = e[1]
答案 1 :(得分:1)
你可以这样做:
reformed_bookings=[]
for item in bookings:
obj = {}
obj['id']=e[0]
obj['date']=e[1]
...
...
reformed_bookings.append(obj)