Skip to content

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

Merged
merged 2 commits into from
Apr 8, 2018

Conversation

rhettinger
Copy link
Contributor

"Prepend a single value in front of an iterator"
# prepend(1, [2, 3, 4]) -> 1 2 3 4
return chain([value], iterator)

Copy link
Member

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)
Copy link
Member

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.

@serhiy-storchaka serhiy-storchaka removed their assignment Apr 8, 2018
@rhettinger rhettinger merged commit 9265dd7 into python:master Apr 8, 2018
@miss-islington
Copy link
Contributor

Thanks @rhettinger for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@bedevere-bot
Copy link

GH-6421 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 8, 2018
(cherry picked from commit 9265dd7)

Co-authored-by: Raymond Hettinger <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Apr 8, 2018
(cherry picked from commit 9265dd7)

Co-authored-by: Raymond Hettinger <[email protected]>
@bedevere-bot
Copy link

GH-6422 is a backport of this pull request to the 3.6 branch.

rhettinger added a commit that referenced this pull request Apr 8, 2018
(cherry picked from commit 9265dd7)

Co-authored-by: Raymond Hettinger <[email protected]>
rhettinger added a commit that referenced this pull request Apr 8, 2018
(cherry picked from commit 9265dd7)

Co-authored-by: Raymond Hettinger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants