From 70c2dd306f575e8bc9edb10ced5c7a6a555d1c87 Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 7 Sep 2017 23:53:07 -0700 Subject: [PATCH] Show example of itemgetter() applied to a dictionary (#3431) --- Doc/library/operator.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 8121b480cb6..76335b179c5 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: