summaryrefslogtreecommitdiffstats
path: root/Doc/library
diff options
context:
space:
mode:
authorRaymond Hettinger <rhettinger@users.noreply.github.com>2017-09-08 06:53:07 (GMT)
committerGitHub <noreply@github.com>2017-09-08 06:53:07 (GMT)
commit70c2dd306f575e8bc9edb10ced5c7a6a555d1c87 (patch)
treeece351132c99b2dc396e617d285184ccc17bc138 /Doc/library
parent8e0ad46bc8349bf92f5f7b8545385b8798c94b52 (diff)
downloadcpython-70c2dd306f575e8bc9edb10ced5c7a6a555d1c87.zip
cpython-70c2dd306f575e8bc9edb10ced5c7a6a555d1c87.tar.gz
cpython-70c2dd306f575e8bc9edb10ced5c7a6a555d1c87.tar.bz2
Show example of itemgetter() applied to a dictionary (#3431)
Diffstat (limited to 'Doc/library')
-rw-r--r--Doc/library/operator.rst3
1 files changed, 3 insertions, 0 deletions
diff --git a/Doc/library/operator.rst b/Doc/library/operator.rst
index 8121b48..76335b1 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: