osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

itertools cycle() docs question


On Fri, Aug 23, 2019 at 1:41 AM Dennis Lee Bieber <wlfraed at ix.netcom.com> wrote:
>
> On Wed, 21 Aug 2019 12:52:44 -0700, Tobiah <toby at tobiah.org> declaimed the
> following:
>
> >
> >I see.  What is an example of an iterable that is not reusable?
>
>
> >>> x = range(5)
> >>> x
> range(0, 5)
> >>>
>

>>> x = range(0, 5)
>>> list(x)
[0, 1, 2, 3, 4]
>>> list(x)
[0, 1, 2, 3, 4]
>>> list(x)
[0, 1, 2, 3, 4]
>>> list(x)
[0, 1, 2, 3, 4]

Perfectly reusable. There are plenty of others that aren't, but that one is.

ChrisA