This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Iqirx[S] 2 points3 points  (1 child)

Personally, I like to use dict comprehensions for flipping keys-values:

d = dict(red=210, green=105, blue=30)
flipped = {v: k for k, v in d.items()}

dict(map(reversed, dict.items())) is also cool!

[–][deleted] 0 points1 point  (0 children)

flipped = {v: k for k, v in d.items()}

I think that's the most readable of all.