reverse a list of Ordered pair in python

Nil*_*far -1 python python-3.x

I have a list of Ordered pair in python like [(1,45),(21,28),(43,110),(4,81)] and I want to reverse each items in list like [(45,1),(28,21),(110,43),(81,4)]. what should I do?

ruo*_*ola 6

Just use a list comprehension with tuple unpacking, it's as simple as:

ls = [(1,45),(21,28),(43,110),(4,81)]
new_ls = [(m, n) for n, m in ls]
print(new_ls)
Run Code Online (Sandbox Code Playgroud)

Output:

[(45, 1), (28, 21), (110, 43), (81, 4)]
Run Code Online (Sandbox Code Playgroud)