[Python-ideas] dict.items to accept optional iterable with keys to use
Sven Marnach
sven at marnach.net
Wed Apr 4 19:01:58 CEST 2012
Victor Varvariuc schrieb am Wed, 04. Apr 2012, um 11:07:55 +0300:
> Sometimes you want a dict which is subset of another dict. It would nice if
> dict.items accepted an optional list of keys to return. If no keys are
> given - use default behavior - get all items.
How about using `operator.itemgetter()`?
from operator import itemgetter
itemgetter(*keys)(my_dict)
It will return a tuple of the values corresponding to the given keys.
Cheers,
Sven
More information about the Python-ideas
mailing list