可以一次附加多个列表吗?(Python) [英] Possible to append multiple lists at once? (Python)
本文介绍了可以一次附加多个列表吗?(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一堆列表,我想附加到一个列表中,该列表是我正在尝试编写的程序中的主"列表.有没有办法在一行代码中而不是像 10 行那样做到这一点?我是初学者所以我不知道...
I have a bunch of lists I want to append to a single list that is sort of the "main" list in a program I'm trying to write. Is there a way to do this in one line of code rather than like 10? I'm a beginner so I have no idea...
为了更好地了解我的问题,如果我有这些列表会怎样:
For a better picture of my question, what if I had these lists:
x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
并且想要将 y 和 z 附加到 x.而不是做:
And want to append y and z to x. Instead of doing:
x.append(y)
x.append(z)
有没有办法在一行代码中做到这一点?我已经试过了:
Is there a way to do this in one line of code? I already tried:
x.append(y, z)
它行不通.
推荐答案
x.extend(y+z)
应该做你想做的
或
x += y+z
甚至
x = x+y+z
这篇关于可以一次附加多个列表吗?(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文