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

itertools roundrobin() #38672

Closed
jackdied opened this issue Jun 17, 2003 · 9 comments
Closed

itertools roundrobin() #38672

jackdied opened this issue Jun 17, 2003 · 9 comments
Assignees
Labels
extension-modules C modules in the Modules dir

Comments

@jackdied
Copy link
Contributor

BPO 756253
Nosy @rhettinger, @jackdied
Files
  • itertoolsmodule.c.diff: Modules/itertoolsmodule.c context diff against cvs
  • test_itertools.py.diff: Lib/test/test_itertools.py patch
  • itertoolsmodule.c: cleaned up patch
  • libitertools.text.diff: documentation path
  • test_itertools.py: updated test patch
  • 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 2004-04-30.22:58:02.000>
    created_at = <Date 2003-06-17.21:35:14.000>
    labels = ['extension-modules']
    title = 'itertools roundrobin()'
    updated_at = <Date 2004-04-30.22:58:02.000>
    user = 'https://github.com/jackdied'

    bugs.python.org fields:

    activity = <Date 2004-04-30.22:58:02.000>
    actor = 'rhettinger'
    assignee = 'rhettinger'
    closed = True
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2003-06-17.21:35:14.000>
    creator = 'jackdied'
    dependencies = []
    files = ['5391', '5392', '5393', '5394', '5395']
    hgrepos = []
    issue_num = 756253
    keywords = ['patch']
    message_count = 9.0
    messages = ['44061', '44062', '44063', '44064', '44065', '44066', '44067', '44068', '44069']
    nosy_count = 2.0
    nosy_names = ['rhettinger', 'jackdied']
    pr_nums = []
    priority = 'normal'
    resolution = 'rejected'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue756253'
    versions = ['Python 2.4']

    @jackdied
    Copy link
    Contributor Author

    a patch to add the roundrobin() and window() objects to
    the itertools module. Hettinger has already seen the
    implementation of roundrobin, but not window.

    test_itertools.py in a seperate patch

    @jackdied jackdied added the extension-modules C modules in the Modules dir label Jun 17, 2003
    @jackdied jackdied added the extension-modules C modules in the Modules dir label Jun 17, 2003
    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    *Please post the tests to this patch and close the other patch.

    *Add a documentation patch to this patch

    *Let's drop the addition of window(). The C code for it is less
    than beautiful and offers only a minimal performance gain
    over the pure python equivalent. I've added the pure python
    version to the docs so folks can cut and paste it if they need
    it. Sorry for the wild goose chase (I had expected the C
    version to be much cleaner and faster and that the python
    verions would've been harder -- actual code was needed for
    me to see it).

    • In roundrobin_next(), replace the % operator with:
      if (lz->iternum==lz->itersize) lz-iternum=0;

    • In roundrobin_next(), remove the extra blank line
      following "long listsize;"

    • Fixup the indentation, currently it is a mix of spaces and
      tabs. It should be just pure tabs.

    • Replace the variable name 'lz' with 'rr'. I should have
      changed that in other places too but for new code it
      should be fixed.

    • 'unti' is mispelled in the docstring.

    @jackdied
    Copy link
    Contributor Author

    Logged In: YES
    user_id=591932

    added Lib/test/test_itertools.py patch here, deleted old
    item that just had that patch in it

    @jackdied
    Copy link
    Contributor Author

    Logged In: YES
    user_id=591932

    pushed to 2.4
    I'll put up patches that incorporate rhettinger's feedback
    soon, and definitely in time for the 2.4 branch.

    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    Great. I look forward to it.

    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    Jack, are you still working on this one?

    @jackdied
    Copy link
    Contributor Author

    jackdied commented Sep 3, 2003

    Logged In: YES
    user_id=591932

    The newest triplet of module/test/documentation incorporate
    your change suggestions. That includes the removal of the
    window() stuff, so these only contain roundrobin() related
    patches.

    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    Decided not to include this in Py2.4.

    The tool is not sufficiently general. It has only one use
    case and arguably that case is better served with
    collections.deque().

    The point in favor of the tool is that it cannot be
    constructed from other itertools.

    @rhettinger
    Copy link
    Contributor

    Logged In: YES
    user_id=80475

    For the record, here a simple and efficient roundrobin task
    server based on collections.deque:

    def roundrobin(*iterables):
        pending = deque(iter(i).next for i in iterables)
        gettask, scheduletask = pending.popleft, pending.append
        while pending:
            task = gettask()
            try:
                yield task()
            except StopIteration:
                continue
            scheduletask(task)
    
    for value in roundrobin('abc', 'd', 'efgh'):
        print value

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    extension-modules C modules in the Modules dir
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants