什么是精简的pythonic非现场版本的扩展?我厌倦了写作
x = [ 1,2,3 ]
x.extend([4,5])
f(x)
只想:
f( x.extend( [4,5], inplace=False ) )
或其他什么
答案 0 :(得分:2)
如何使用+
运算符
def f(l):
return l
x = [1,2,3]
>>> id(x)
48474312 # Note the id
>>> x = f(x + [4,5])
[1, 2, 3, 4, 5]
>>> id(x)
43637016 # Different id, that means not in-place