Propose a getitem() method
This commit is contained in:
parent
ccf55361f8
commit
0aedc93c61
17
pep-0455.txt
17
pep-0455.txt
|
@ -95,6 +95,23 @@ constructors::
|
|||
>>> sorted(d.items())
|
||||
[('Bar', 2), ('Foo', 1)]
|
||||
|
||||
Getting the original key
|
||||
------------------------
|
||||
|
||||
TransformDict also features a lookup method returning the stored key
|
||||
together with the corresponding value::
|
||||
|
||||
>>> d = TransformDict(str.casefold, {'Foo': 1})
|
||||
>>> d.getitem('FOO')
|
||||
('Foo', 1)
|
||||
>>> d.getitem('bar')
|
||||
Traceback (most recent call last):
|
||||
File "<stdin>", line 1, in <module>
|
||||
KeyError: 'bar'
|
||||
|
||||
The method name ``getitem()`` mirrors the standard ``popitem()`` method
|
||||
on mutable mappings.
|
||||
|
||||
|
||||
Alternative proposals and questions
|
||||
===================================
|
||||
|
|
Loading…
Reference in New Issue