0

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])]

wormyworm
  • 179
  • 8

3 Answers3

3

You can flip each tuple by:

L = [(b, a) for a, b in L]
Dan D.
  • 73,243
  • 15
  • 104
  • 123
2

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])]
Mykola Zotko
  • 15,583
  • 3
  • 71
  • 73
1

You can do the following:

items = [4,3],[1,2]
L = items[::-1]
print(L) # output[([1,2], [4,3])]
Rafael Laurindo
  • 474
  • 2
  • 7