Python 使用字典中的列表
我试着在一张单子里用一张单子。 所以我想做的是使用Python 使用字典中的列表,python,list,dictionary,nested,Python,List,Dictionary,Nested,我试着在一张单子里用一张单子。 所以我想做的是使用 add_counter = 0 put_lst = [] while add_counter <= len(add_account_data_mutable)-1: put_lst.append( { 'PutRequest': { 'Item'
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
}}
})
有人能帮帮我吗。改变:
'PutRequest': {
'Item': {
list_i_want_to_use[add_counter]
}
}
致:
要使用[添加计数器]的值
列表已具有类型dict
,因此您可以直接使用它。通过将其用花括号括起来,您构建了一个set
,将dict
值作为一个元素,这是不允许的,因为dict
值是不可破坏的。您可以使用字典中的列表,可能是'Item':list\u我想使用[add\u counter]
显示堆栈跟踪并修复缩进
'PutRequest': {
'Item': {
list_i_want_to_use[add_counter]
}
}
'PutRequest': {
'Item': list_i_want_to_use[add_counter]
}