-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
Add a prepend() recipe to teach a chain() idiom #6415
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
Conversation
Doc/library/itertools.rst
Outdated
"Prepend a single value in front of an iterator" | ||
# prepend(1, [2, 3, 4]) -> 1 2 3 4 | ||
return chain([value], iterator) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trailing spaces.
def prepend(value, iterator): | ||
"Prepend a single value in front of an iterator" | ||
# prepend(1, [2, 3, 4]) -> 1 2 3 4 | ||
return chain([value], iterator) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A tuple would be a tiny bit faster, but look more obscure.
Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7. |
GH-6421 is a backport of this pull request to the 3.7 branch. |
(cherry picked from commit 9265dd7) Co-authored-by: Raymond Hettinger <[email protected]>
(cherry picked from commit 9265dd7) Co-authored-by: Raymond Hettinger <[email protected]>
GH-6422 is a backport of this pull request to the 3.6 branch. |
(cherry picked from commit 9265dd7) Co-authored-by: Raymond Hettinger <[email protected]>
(cherry picked from commit 9265dd7) Co-authored-by: Raymond Hettinger <[email protected]>
See discussion at: https://mail.python.org/pipermail/python-ideas/2018-April/049652.html