the python utility 'reverse' is reversing in-place. if you need a new list of reversed items? In such case the original list should be copied (by the member utility 'copy') into the new list and the function 'revers' applied on the new list:
a=[1,2,3,4,5]
Shevach Riabtsev
the python utility 'reverse' is reversing in-place. if you need a new list of reversed items? In such case the original list should be copied (by the member utility 'copy') into the new list and the function 'revers' applied on the new list: a=[1,2,3,4,5]
b=a.copy()
'b' and 'a' are different objects
id(a) 80088808
id(b) 8526344
print(b) [ 1,2,3,4,5]
b.reverse()
print(b) [5, 4, 3, 2, 1]