How can I reverse the order of these items?
L = []
items = [4,3],[1,2]
L.append(items)
## reverse the order of items in L such that L contains : [([1,2],[4,3])]
Reverse the order of items in L such that L contains : [([1,2],[4,3])]
How can I reverse the order of these items?
L = []
items = [4,3],[1,2]
L.append(items)
## reverse the order of items in L such that L contains : [([1,2],[4,3])]
Reverse the order of items in L such that L contains : [([1,2],[4,3])]
You can use the function reversed()
to reverse the order of elements in the array:
L = []
items = [4,3],[1,2]
L.append(items)
L = [tuple(reversed(i)) for i in L]
# [([1, 2], [4, 3])]
Alternatively you can use:
L = [(i[1], i[0]) for i in L]
or
L = [(L[0][1], L[0][0])]
You can do the following:
items = [4,3],[1,2]
L = items[::-1]
print(L) # output[([1,2], [4,3])]