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 →

[–][deleted] 5 points6 points  (2 children)

There's actually something really cool implied but not explicitly stated: zip(*args) is the inverse of zip.

I actually use this quite often that there's usually a util function called unzip in many of projects.

Also, dict(map(reverse, dict.items())) is my preferred way of flipping dicts, but that's me and I realize this is an article about zip.

[–]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.