Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 70c2dd3

Browse files
authored
Show example of itemgetter() applied to a dictionary (#3431)
1 parent 8e0ad46 commit 70c2dd3

1 file changed

Lines changed: 3 additions & 0 deletions

File tree

Doc/library/operator.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,9 @@ expect a function argument.
321321
>>> itemgetter(slice(2,None))('ABCDEFG')
322322
'CDEFG'
323323

324+
>>> soldier = dict(rank='captain', name='dotterbart')
325+
>>> itemgetter('rank')(soldier)
326+
'captain'
324327

325328
Example of using :func:`itemgetter` to retrieve specific fields from a
326329
tuple record:

0 commit comments

Comments
 (0)