From: Raymond Hettinger Date: Fri, 8 Sep 2017 06:53:07 +0000 (-0700) Subject: Show example of itemgetter() applied to a dictionary (#3431) X-Git-Tag: v3.7.0a1~100 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=70c2dd306f575e8bc9edb10ced5c7a6a555d1c87;p=python Show example of itemgetter() applied to a dictionary (#3431) --- diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 8121b480cb..76335b179c 100644 --- a/Doc/library/operator.rst +++ b/Doc/library/operator.rst @@ -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: