可以一次附加多个列表吗? (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