Skip to content

Add a prepend() recipe to teach a chain() idiom#6415

Merged
rhettinger merged 2 commits intopython:masterfrom
rhettinger:itertools-prepend-recipe
Apr 8, 2018
Merged

Add a prepend() recipe to teach a chain() idiom#6415
rhettinger merged 2 commits intopython:masterfrom
rhettinger:itertools-prepend-recipe

Conversation

@rhettinger
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor

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

@bedevere-bot
Copy link
Copy Markdown

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 <rhettinger@users.noreply.github.com>
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 <rhettinger@users.noreply.github.com>
@bedevere-bot
Copy link
Copy Markdown

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 <rhettinger@users.noreply.github.com>
rhettinger added a commit that referenced this pull request Apr 8, 2018
(cherry picked from commit 9265dd7)

Co-authored-by: Raymond Hettinger <rhettinger@users.noreply.github.com>
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