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/2004-September/049063.html below:

[Python-Dev] Re: A cute new way to get an infinite loop

[Python-Dev] Re: A cute new way to get an infinite loop [Python-Dev] Re: A cute new way to get an infinite loopBeni Cherniavsky cben at users.sf.net
Thu Sep 23 19:24:35 CEST 2004
Tim Peters wrote:
>>>>x = [1]
>>>>x.extend(-y for y in x)
> 
A simpler way:

 >>> x = [1, -1]
 >>> x.extend(iter(x))

Curiously, this didn't "work" before 2.4 either:

 >>> x = [1]
 >>> x.extend(iter(x))
 >>> x
[1, 1]

The iterator did see the new elements after the extend call but not
during it:

 >>> x = [1]
 >>> i = iter(x)
 >>> x.extend(x)
 >>> list(i)
[1, 1]
 >>> x = [1]
 >>> i = iter(x)
 >>> x.extend([list(i)])
 >>> x
[1, [1]]

The reason is that in 2.3 `listextend()` passed the right argument
through `PySequence_Fast` which copied it before beggining to extend
the list.

It's much better now.  I mean it!  Bugs should be predictable.
Infinite loop should never terminate silently.  Unless explicitly
terminated.

More information about the Python-Dev mailing list

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