[Python-ideas] Add dict.getkey() and set.get()
Serhiy Storchaka
storchaka at gmail.com
Sat Sep 14 17:09:15 CEST 2013
I propose to add two methods:
dict.getkey(key) returns original key stored in the dict which is equal
to specified key. E.g.
>>> d = {2: 'a', 5.0: 'b'}
>>> d.getkey(2.0)
2
>>> d.getkey(5)
5.0
>>> d.getkey(17)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 17
set.get(value) returns original value stored in the set which is equal
to specified value. E.g.
>>> s = {2, 5.0}
>>> s.get(2.0)
2
>>> s.get(5)
5.0
>>> s.get(17)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 17
More information about the Python-ideas
mailing list