counting using variable length string as base

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Thu Mar 27 09:45:20 CET 2008


On Thu, 27 Mar 2008 00:33:21 -0700, Grimsqueaker wrote:

> That seems to give me the items in the list back in an iterator. Am I
> using it incorrectly?

Given an iterator, you use it like this:

for item in iterator:
    print item # or do something else


If you're sure that the iterator is relatively small, you can do this:

give_me_everything_at_once = list(iterator)


but don't try that with this one:


def ones():  # never-ending series of ones
    while True:
        yield 1

iterator = ones()


-- 
Steven



More information about the Python-list mailing list