From ee65ca9174f8d430790e6eb302522a8b59f6bc0c Mon Sep 17 00:00:00 2001 From: Raymond Hettinger Date: Thu, 7 Sep 2017 14:11:18 -0700 Subject: [PATCH] Show example of itemgetter() applied to a dictionary --- Doc/library/operator.rst | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst index 8121b480cb6574..76335b179c58f8 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: