How do I reverse tuples in a list of tuples using python? -
this question has answer here:
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
Post a Comment