A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2001-July/016378.html below:

[Python-Dev] Iterator addition?

[Python-Dev] Iterator addition? [Python-Dev] Iterator addition?Just van Rossum just@letterror.com
Mon, 30 Jul 2001 10:53:35 +0200
Moshe Zadka wrote:

> No, instead of:
> 
> 
> class concat:
> 
>     def __init__(self, *iterators):
>         self.iterators = list(iterators)
> 
>     def __iter__(self): return self
> 
>     def next(self):
>         while self.iterators:
>             try:
>                 return self.iterators[0].next() 
>             except StopIteration:
>                 del self.iterators[0]
>         else:
>             raise StopIteration
> 
> 
> for x in concat(iter1, iter2):
>     do_something(x)

Or:

from __future__ import generators

def concat(*iterators):
    for i in iterators:
        for x in i:
            yield x

for x in concat(iter1, iter2):
    do_something(x)


Just



RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4