Skip to content

Modification to "pairwise" in itertools recipes #49600

Closed

Description

@della
mannequin
BPO 5350
Nosy @birkenfeld, @rhettinger

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 2009-02-23.19:40:08.891>
created_at = <Date 2009-02-23.13:37:11.058>
labels = ['docs']
title = 'Modification to "pairwise" in itertools recipes'
updated_at = <Date 2009-02-23.21:57:27.667>
user = 'https://bugs.python.org/della'

bugs.python.org fields:

activity = <Date 2009-02-23.21:57:27.667>
actor = 'della'
assignee = 'rhettinger'
closed = True
closed_date = <Date 2009-02-23.19:40:08.891>
closer = 'rhettinger'
components = ['Documentation']
creation = <Date 2009-02-23.13:37:11.058>
creator = 'della'
dependencies = []
files = []
hgrepos = []
issue_num = 5350
keywords = []
message_count = 7.0
messages = ['82626', '82627', '82630', '82638', '82640', '82641', '82646']
nosy_count = 4.0
nosy_names = ['georg.brandl', 'rhettinger', 'LambertDW', 'della']
pr_nums = []
priority = 'normal'
resolution = 'accepted'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue5350'
versions = []

Activity

  1. della commented on Feb 23, 2009

    dellamannequin
    MannequinAuthor

    I feel that the "pairwise" recipe could be slightly more elegant if "for
    elem in b: break" became a simpler next(b) (or b.next() for Python 2.x).
    It is also more natural to modify the recipes to suit one's needs (e.g.,
    returning items with a given gap between them, or convert the recipe to
    k-wise iteration).

  2. added
    docsDocumentation in the Doc dir
    on Feb 23, 2009
  3. birkenfeld commented on Feb 23, 2009

    @birkenfeld
    Member

    Assigning to Raymond.

    Note that "for elem in b: break" and "next(b)" are not equivalent when b
    is empty/exhausted.

  4. della commented on Feb 23, 2009

    dellamannequin
    MannequinAuthor

    Georg, you're right, there's a StopIteration to catch. My thinko was
    mistaking the function for a generator where the exception propagation
    would have done the right thing. The amended version now becomes

    next(b)
    for x, y in zip(a, b): yield x, y

    ...which is not that attractive anymore, also because it's slower. Sorry
    for the error.

  5. rhettinger commented on Feb 23, 2009

    @rhettinger
    Contributor

    Applied in r69908 .

  6. lambertdw commented on Feb 23, 2009

    lambertdwmannequin
    Mannequin

    Nice. I had thought of this a while ago but found counter example,
    probably using the empty iterator

    def f():
        raise StopIteration
        yield

    I didn't realize "next" had optional argument.

  7. birkenfeld commented on Feb 23, 2009

    @birkenfeld
    Member

    Shame on me, I forgot about the optional argument too.

  8. della commented on Feb 23, 2009

    dellamannequin
    MannequinAuthor

    great Raymond! :)

  9. transferred this issue fromon Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dir

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions