How do I reverse tuples in a list of tuples using python? -


given list of tuples:

l = [(1, 'a'), (2, 'b'), (3, 'c'), (4, 'd'), (5, 'e')] 

i'd find quickest , simplest way reverse each individual tuple in x, get:

[('a', 1), ('b', 2), ('c', 3), ('d', 4), ('e', 5)] 

i'm sure there's simple way this, i'm not sure how. how can done?


p.s.: let me know if duplicate exists. i've searched , haven't found one.

l2 = [t[::-1] t in l] 

use standard negative-step slicing t[::-1] reverse of tuple, , list comprehension each tuple.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -