Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用字典中的列表_Python_List_Dictionary_Nested - Fatal编程技术网

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]
}