Skip to content
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

Add an intersperse function to itertools #65613

Closed
javawizard mannequin opened this issue May 2, 2014 · 4 comments
Closed

Add an intersperse function to itertools #65613

javawizard mannequin opened this issue May 2, 2014 · 4 comments
Assignees
Labels
type-feature A feature request or enhancement

Comments

@javawizard
Copy link
Mannequin

javawizard mannequin commented May 2, 2014

BPO 21414
Nosy @rhettinger, @merwok

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/rhettinger'
closed_at = <Date 2014-05-04.02:13:34.387>
created_at = <Date 2014-05-02.07:39:41.789>
labels = ['type-feature']
title = 'Add an intersperse function to itertools'
updated_at = <Date 2014-05-04.02:13:34.385>
user = 'https://bugs.python.org/javawizard'

bugs.python.org fields:

activity = <Date 2014-05-04.02:13:34.385>
actor = 'rhettinger'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2014-05-04.02:13:34.387>
closer = 'rhettinger'
components = []
creation = <Date 2014-05-02.07:39:41.789>
creator = 'javawizard'
dependencies = []
files = []
hgrepos = []
issue_num = 21414
keywords = []
message_count = 4.0
messages = ['217746', '217764', '217814', '217854']
nosy_count = 4.0
nosy_names = ['rhettinger', 'eric.araujo', 'cvrebert', 'javawizard']
pr_nums = []
priority = 'normal'
resolution = 'rejected'
stage = None
status = 'closed'
superseder = None
type = 'enhancement'
url = 'https://bugs.python.org/issue21414'
versions = ['Python 3.5']

@javawizard
Copy link
Mannequin Author

javawizard mannequin commented May 2, 2014

Itertools would benefit greatly from a function (which I've named intersperse, after Haskell's equivalent) for yielding the items of an iterator with a given value placed between each. Sort of a str.join-like function, but for arbitrary sequences.

Something like:

>>> list(itertools.intersperse(1, [2, 3, 4]))
[2, 1, 3, 1, 4]

@javawizard javawizard mannequin added the type-feature A feature request or enhancement label May 2, 2014
@merwok
Copy link
Member

merwok commented May 2, 2014

I looked for a previous discussion of this on the Python mailing lists and found nothing.

Existing solutions include https://twitter.com/snim2/status/393821419114483712 and http://stackoverflow.com/questions/5655708/python-most-elegant-way-to-intersperse-a-list-with-an-element

Raymond is the one to decide whether this should be added. If he doesn't comment in the near future, feel free to propose this on python-ideas to see if people like it. You may also want to ask maintainers of projects like more-itertools if they have a similar function and if people use it.

@rhettinger
Copy link
Contributor

What is the use case for interspersing values? I've not run across anything like it ever before.

@rhettinger rhettinger self-assigned this May 3, 2014
@rhettinger
Copy link
Contributor

I've looked into this a bit more. Even in Haskell, it seems that use case is for str.join() which we already have. I don't see intersperse() in any other functional languages. That suggests that its use cases aren't sufficiently common to warrant adding it to the standard library.

Thank you for the submission.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

2 participants