python中扩展运算符的非就地版本

Qua*_*ant 3 python

什么是扩展的简洁 pythonic 非就地版本?我厌倦了写作

x = [ 1,2,3 ]
x.extend([4,5])
f(x)
Run Code Online (Sandbox Code Playgroud)

只是想:

 f( x.extend( [4,5], inplace=False ) )
Run Code Online (Sandbox Code Playgroud)

管他呢

Cor*_*mer 5

只使用+运算符怎么样

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
Run Code Online (Sandbox Code Playgroud)