Is it not possible to have mutability without this? I know I can use
sorted and list(reversed) instead of .sort and .reverse but if I want
to copy a list and then change that list without changing the first
one?
And there isn't a .copy function so I have to "new = [] for element in
list: new.append(elem ent)" ?
(I guess mutability is there for performance? Because I prefer a =
sorted(a) conceptually.)
[1, 2, 3, 4]
[1, 2, 3, 4]
'hello'
'hello sir!'
and what is the difference between extend and + on lists?
sorted and list(reversed) instead of .sort and .reverse but if I want
to copy a list and then change that list without changing the first
one?
And there isn't a .copy function so I have to "new = [] for element in
list: new.append(elem ent)" ?
(I guess mutability is there for performance? Because I prefer a =
sorted(a) conceptually.)
>>a = [1,2,3]
>>b = a
>>b.append(4)
>>b
>>b = a
>>b.append(4)
>>b
>>a
>>c = "hello"
>>d = c
>>d += " sir!"
>>c
>>d = c
>>d += " sir!"
>>c
>>d
>>>
and what is the difference between extend and + on lists?
Comment