python - python中字典内的列表
问题描述
我目前正在尝试以这种格式将包含列表的字典插入到我的 MongoDB 数据库中:
guildId: myDiscordGuildId,
questions: [
'Do you like waffles?',
'Who put the bop in the bop shoo bop shoo bop?'
]
但是,这是一个 Javascript 集合。但是,我使用 python,我不确定如何做到这一点。
我知道如何将列表放入字典中,如下所示:
mydict = {'fruits': ['banana', 'apple', 'orange'],
'vegetables': ['pepper', 'carrot'],
'cheese': ['swiss', 'cheddar', 'brie']}
但是,如果我的列表是这样定义的变量:
我的列表 = []
我如何在字典中使用这个列表变量来获得与上面的水果字典相同的结果?
这个列表是通过我的不和谐机器人操作的,并且被改变了。
当值被硬编码时,我知道如何在字典中使用列表。但是当使用变量时我不确定。
解决方案
new_application = {
"guildId": ctx.author.id,
"questions": questions
}
固定的
推荐阅读
- python - python numpy:ValueError:形状(14,)和(404,14)未对齐:14(dim 0)!= 404(dim 0)
- php - PHP SOAP 请求未填充 XML 参数
- javascript - 未捕获的类型错误:无法读取未定义的属性“事务”,内容库
- c - 如何在 C 中为 getch() 函数定义某个时间?
- python - 获取 AttributeError:模块 'django.db.models' 在 Django 1.11 中没有属性 'UniqueConstraint'
- mongodb - MongoDB Map-Reduce:需要合并到所有其他匹配条件的文档中?
- angular - Angular - 在应用程序组件中获取路由数据
- c# - Why the value of "count" is showig 1 instead of 2?
- reactjs - React website not showing after deployment with firebase
- wordpress - 如何修复 Hugo CMS 中的错误`found no layout file for "html" for "page"`?