Python Roads of Reverse List
In Python programming, we often need to reverse a list. Suppose there is a list:
[1, 2, 3, 4, 5], we need to get the inverse sequence list of this list, [5, 4, 3, 2, 1].
First, let us prepare the source list:
>>> source_list = [1, 2, 3, 4, 5]
Road O...
dormouse.hashnode.dev3 min read
Shevach Riabtsev
video compression and streaming
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]