Propose a getitem() method

This commit is contained in:
Antoine Pitrou 2013-09-13 23:48:33 +02:00
parent ccf55361f8
commit 0aedc93c61
1 changed files with 17 additions and 0 deletions

View File

@ -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
===================================