I had no idea Python could do this, but Ruff taught me something new this morning. Suppose I want to transform a dict
into a set
of tuples
. You can do it in a single line, with no comprehension required!
mydict = {
'a': 123,
'b': 456,
'c': 789,
}
myset = set(mydict.items())
# myset is now: {('a', 123), ('b', 456), ('c', 789)}
I love stumbling upon little hidden gems like this!