mirror of
https://github.com/python/cpython.git
synced 2025-12-23 09:19:18 +00:00
[doc] Remove duplicated operator.itemgetter example (GH-24178) (#25646)
* Remove duplicated itemgetter example
* Add spaces
(cherry picked from commit 743e2bae10)
Co-authored-by: Andre Delfino <adelfino@gmail.com>
This commit is contained in:
parent
c816c1c779
commit
4a3d73d8ad
1 changed files with 2 additions and 5 deletions
|
|
@ -315,15 +315,12 @@ expect a function argument.
|
|||
method. Dictionaries accept any hashable value. Lists, tuples, and
|
||||
strings accept an index or a slice:
|
||||
|
||||
>>> itemgetter('name')({'name': 'tu', 'age': 18})
|
||||
'tu'
|
||||
>>> itemgetter(1)('ABCDEFG')
|
||||
'B'
|
||||
>>> itemgetter(1,3,5)('ABCDEFG')
|
||||
>>> itemgetter(1, 3, 5)('ABCDEFG')
|
||||
('B', 'D', 'F')
|
||||
>>> itemgetter(slice(2,None))('ABCDEFG')
|
||||
>>> itemgetter(slice(2, None))('ABCDEFG')
|
||||
'CDEFG'
|
||||
|
||||
>>> soldier = dict(rank='captain', name='dotterbart')
|
||||
>>> itemgetter('rank')(soldier)
|
||||
'captain'
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue