I think these are an extremely common needs that are worth having standard
methods for. If adding instance methods seems like a bad idea, then maybe add
functions to the standard library that perform the same operations.
m = {'a': 123, 'b': 456, 'c': 789}
m.except(('a', 'c')) # {'b': 456}
m.only(('b', 'c')) # {'b': 456, 'c': 789}
m.values_at(('a', 'b')) # [123, 456]
…or…
from mappings import except, only, values_at
m = {'a': 123, 'b': 456, 'c': 789}
except(m, ('a', 'c')) # {'b': 456}
only(m, ('b', 'c')) # {'b': 456, 'c': 789}
values_at(m, ('a', 'b')) # [123, 456]
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/SMHI3ABM4XLASYYDGSTY45BKHTM7QMK2/
Code of Conduct: http://python.org/psf/codeofconduct/