I am afraid that in the long layoff in python has meant some new constructs have passed me by. In googling around I found some nice little code I want to use, but i don't quite understand it, how it is called, and what it is an example of. I guess there are generators and iterators now and it seems this might be an example of one of those new constructs. Can anyone explain what it is i am looking at, how it is called, and what it is an example of so that I can look it up:

def roundrobin(*iterables):
    "roundrobin('ABC', 'D', 'EF') --> A D E B F C"
    # Recipe credited to George Sakkis
    pending = len(iterables)
    nexts = cycle(iter(it).next for it in iterables)
    while pending:
        try:
            for next in nexts:
                yield next()
        except StopIteration:
            pending -= 1
            nexts = cycle(islice(nexts, pending))
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to