Can this be reduced to a single line (after assigning a
)?
a = [1,2,3]
b = a[:]
b.append(4)
Can this be reduced to a single line (after assigning a
)?
a = [1,2,3]
b = a[:]
b.append(4)
The following is probably the simplest:
b = a + [4]
Here, you don't need a[:]
since we're no longer copying the reference (+
creates and returns a new list anyway).