Python:合并字典列表

Cos*_*eal 5 python merge dictionary iterator list

我在字典里面有列表:

Number_of_lists=3           #user sets this value, can be any positive integer
My_list={}
for j in range(1,Number_of_lists+1):
  My_list[j]=[(x,y,z)]  
Run Code Online (Sandbox Code Playgroud)

Number_of_lists是用户设置的变量.如果事先不知道用户设置的值,我想最终得到所有字典列表的合并列表.例如,如果Number_of_lists=3和相应的列表是My_list[1]=[(1,2,3)],My_list[2]=[(4,5,6)],My_list[3]=[(7,8,9)]结果将是:

All_my_lists=My_list[1]+My_list[2]+My_list[3]
Run Code Online (Sandbox Code Playgroud)

哪里: All_my_lists=[(1,2,3),(4,5,6),(7,8,9)].

所以我要做的就是尽可能自动执行上述过程:

Number_of_lists=n #where n can be any positive integer

我有点迷失到现在尝试使用迭代器添加列表并始终失败.我是一个蟒蛇初学者,这是我的一个爱好,所以如果你回答请解释你的答案中的一切我正在做这个学习,我不是要求你做我的功课:)

编辑

@codebox(看下面的评论)正确地指出My_List,我的代码中显示的实际上是字典而不是列表.如果您使用任何代码,请小心.

Ash*_*ary 1

使用列表理解:

>>> Number_of_lists=3 
>>> My_list={}
>>> for j in range(1,Number_of_lists+1):
      My_list[j]=(j,j,j)
>>> All_my_lists=[My_list[x] for x in My_list]

>>> print(All_my_lists)
[(1, 1, 1), (2, 2, 2), (3, 3, 3)]
Run Code Online (Sandbox Code Playgroud)

All_my_lists=[My_list[x] for x in My_list]相当于:

All_my_lists=[]
for key in My_list:
   All_my_lists.append(My_list[key])
Run Code Online (Sandbox Code Playgroud)