]> granicus.if.org Git - python/commitdiff
Show example of itemgetter() applied to a dictionary (#3431)
authorRaymond Hettinger <rhettinger@users.noreply.github.com>
Fri, 8 Sep 2017 06:53:07 +0000 (23:53 -0700)
committerGitHub <noreply@github.com>
Fri, 8 Sep 2017 06:53:07 +0000 (23:53 -0700)
Doc/library/operator.rst

index 8121b480cb65743110fd92f8969591341665c32a..76335b179c58f8c9d4c5ecf6bd00e4059b09093c 100644 (file)
@@ -321,6 +321,9 @@ expect a function argument.
       >>> itemgetter(slice(2,None))('ABCDEFG')
       'CDEFG'
 
+      >>> soldier = dict(rank='captain', name='dotterbart')
+      >>> itemgetter('rank')(soldier)
+      'captain'
 
    Example of using :func:`itemgetter` to retrieve specific fields from a
    tuple record: