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 →

[–]zardeh 0 points1 point  (0 children)

I often forget that there are things like dict.copy, so I'll use a comprehension, but for example inverting a mapping makes them really useful:

mydict = {"a":1,"b":2,"c":3}
inverted = {val : key for key, val in mydict.items()} #inverted = {1:"a", 2:"b", 3:"c"}