[Tutor] Unlimited string

Danny Yoo dyoo at hkn.eecs.berkeley.edu
Mon Aug 30 00:57:01 CEST 2004



On Sun, 29 Aug 2004, Kalle Svensson wrote:

> [noud]
> > I was wondering, is it possible in python to make a unlimited
> > string?
>

[text cut]

> [Kalle]
> Yes.  Using generators, you can construct infinite sequences.  An
> example:
>
>   >>> def positive_integers():
>   ...     x = 1
>   ...     while True:
>   ...         yield x
>   ...         x += 1

[text cut]


Hi Noud,


By the way, there are a set of tools in the Standard Library for play with
with iterators:

    http://docs.python.org/lib/module-itertools.html

The functions there are designed to work with these "infinite" iterators.
In fact, the positive_integers() definitions that Kalle shows is very
similar to itertools.count().


Good luck to you!




More information about the Tutor mailing list