Skip to content

itemgetter add dict example #1280

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 13, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Doc/library/operator.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ 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})
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this shouldn't put here, this code block is for explaining Lists, tuples, and strings accept an index or a slice:, not Dictionaries accept any hashable value.

If we want to add a new example for dictionaries, it should make a new code block above this one.

Copy link
Member

@bitdancer bitdancer Apr 25, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this makes the example exactly parallel the paragraph it follows, showing the dictionary example first, then the index, and then the slice, in the order they are mentioned in the text. Breaking the paragraph up with the example would not improve the flow, in my opinion. The fact that dictionary is in a separate sentence doesn't matter that much, I think.

'tu'
>>> itemgetter(1)('ABCDEFG')
'B'
>>> itemgetter(1,3,5)('ABCDEFG')
Expand Down