These are all far too easy to do with comprehensions to merit new methods or stdlib functions.
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] > {k:m[v] for k in m if k not in ['a','c']} {k:m[v] for k in m if k in ('b','c')}. [m[k] for k in m if k in {'a', 'b'}] The existing versions are a few characters longer, but far more general when you want minor variations. Moreover, I have very rarely wanted to do ANY of the things described by these hypothetical methods. That said, I think maybe something extending PEP 584 could be reasonable, but I'm not quite sure of the semantics. E.g., we might provide additional set-like operators for dicts. >>> m | {'a':"Newval"} # We have this now {'a': 'Newval', 'b': 456, 'c': 789} >>> m - {'a'} # Would rightval be a set or dict though?! {'b': 456, 'c': 789} >>> m & {'a', 'b'} # Same question, but set feels better, I think {'a': 'Newval', 'b': 456} -- Keeping medicines from the bloodstreams of the sick; food from the bellies of the hungry; books from the hands of the uneducated; technology from the underdeveloped; and putting advocates of freedom in prisons. Intellectual property is to the 21st century what the slave trade was to the 16th.
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/B23J2ABBFOOXQYHYSVHX7ILJZRRE2IKH/ Code of Conduct: http://python.org/psf/codeofconduct/