3 ms·
Personally I'd love to see pattern matching / de-structuring of dicts and strings: foobar = "foo{}".format("bar") foo = "{}bar".unformat(foobar) d
by OJFord 10y ago
Personally I'd love to see pattern matching / de-structuring of dicts and strings:
foobar = "foo{}".format("bar")
foo = "{}bar".unformat(foobar)
def dict_returner():
return {'foo': 1, 'bar': 2, 'foobar': 3}
{'foo': newvar1, 'bar': foo} = dict_returner()
I find it strange tuple unpacking exists, but not anything equivalent for dicts - I can't see that it would be horribly inefficient? Especially considering that one would be unlikely to use it with more than a few keys.
An extension to that providing a set of keys would be nice, too:
foo_and_bar = dict_returner(){'foo', 'bar'}