python - 使用字典中的列表
问题描述
我正在尝试在列表中的字典中使用列表。所以我想做的是使用
add_counter = 0
put_lst = []
while add_counter <= len(add_account_data_mutable)-1:
put_lst.append(
{
'PutRequest': {
'Item': {
list_i_want_to_use[add_counter] #this has a dict type
}}
})
我一直在以开头的行收到此错误'Item':{
TypeError: unhashable type: 'dict
有人可以帮帮我吗。
解决方案
改变:
'PutRequest': {
'Item': {
list_i_want_to_use[add_counter]
}
}
至:
'PutRequest': {
'Item': list_i_want_to_use[add_counter]
}
该值list_i_want_to_use[add_counter]
已经具有 type dict
,因此您可以直接使用它。通过将其包裹在大括号中,您将 a 构造为set
将dict
值作为元素,这是不允许的,因为dict
值是不可散列的。
推荐阅读
- sql - 从oracle中的两个不同表中将多行插入一个表中?
- javascript - 使用正则表达式删除奇数空格以在 char 数组中获得偶数个空格
- r - R - 根据因子分类
- sql - 计算 SQL 时的不同大小写
- python - 如何按不同条件过滤列表?
- python - 如何使用 for 循环在 Dash + Python 中显示多个图表?
- java - 根据对象的属性值过滤列表 - Java/Javascript?(首选流/功能类型的方法是首选)
- ionic3 - 在woocommerce rest api中按id检索单个产品或按id检索单个类别时为空结果
- javascript - 使用 JS onsubmit 验证 html 表单
- python - 限制外键 Django 的模型选择