数据列表和空字典键 - 有没有办法将数据按顺序分配给字典键
List of data and an empty dictionary keys - Is there a way to assign the data sequentially to the dictionary key
我有一个字典内容如下
contentDict = {
"Prefecture": "",
"Total List Number": "",
"Title": "",
"Event Validity": "",
"Available Period": "",
"Available StartDate": "",
"End Date": "",
"Last Updated": "",
"mainText": "",
"Location Tag": "",
"Event Tag": "",
"Main Image URL": "",
"innerWebSiteURL": "",
"ListLink": ""
}
和相同长度的内容列表。
有没有办法将列表的每个内容按顺序分配给字典
我尝试使用 zip() 但惨遭失败
字典需要按照指定的顺序排序,因为我想按照提供的顺序将它添加到 mysql 数据库中..
最终目标是使用 to_sql() 方法将字典放入 MySQL 数据库
我最初编码时没有考虑 MySQL,后来被告知使用 ORM to_SQL 方法来传输数据..
如有任何提示或指导,我们将不胜感激
好吧,假设您的列表是 contentList,
contentList = [i for i in range(14)]
有一件事是通过键循环:
for i,k in enumerate(contentDict):
contentDict[k] = contentList[i]
或'pythonically':
contentDict = {k:contentList[i] for i,k in enumerate(contentDict)}
我有一个字典内容如下
contentDict = {
"Prefecture": "",
"Total List Number": "",
"Title": "",
"Event Validity": "",
"Available Period": "",
"Available StartDate": "",
"End Date": "",
"Last Updated": "",
"mainText": "",
"Location Tag": "",
"Event Tag": "",
"Main Image URL": "",
"innerWebSiteURL": "",
"ListLink": ""
}
和相同长度的内容列表。
有没有办法将列表的每个内容按顺序分配给字典
我尝试使用 zip() 但惨遭失败
字典需要按照指定的顺序排序,因为我想按照提供的顺序将它添加到 mysql 数据库中..
最终目标是使用 to_sql() 方法将字典放入 MySQL 数据库
我最初编码时没有考虑 MySQL,后来被告知使用 ORM to_SQL 方法来传输数据..
如有任何提示或指导,我们将不胜感激
好吧,假设您的列表是 contentList,
contentList = [i for i in range(14)]
有一件事是通过键循环:
for i,k in enumerate(contentDict):
contentDict[k] = contentList[i]
或'pythonically':
contentDict = {k:contentList[i] for i,k in enumerate(contentDict)}