Hi all,

It always bothered me to write something like this when i want to strip keys from a dictionnary in Python:

a = {"foo": 1, "bar": 2, "baz": 3, "foobar": 42}
interesting_keys = ["foo", "bar", "baz"]
b = {k, v for k,v in a.items() if k in interesting_keys}

Wouldn't it be nice to have a syntactic sugar such as:

b = a.subset(interesting_keys)

I find this version more elegant/explicit. But maybe this feature is not "worth it"

Cheers !
Python-ideas mailing list
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to