Dear all, with
a=list(range(1,11))
why (in Python 2.7 and 3.3) is this explicit for loop working:
for i in a[:-1]:
a.pop() and a
giving:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5]
[1, 2, 3, 4]
[1, 2, 3]
[1, 2]
[1]
but the equ
On 2013-03-28 15:25, Wolfgang Maier wrote:
> Dear all, with
> a=list(range(1,11))
>
> why (in Python 2.7 and 3.3) is this explicit for loop working:
> for i in a[:-1]:
> a.pop() and a
As you discover:
> Especially, since these two things *do* work as expected:
> [a.pop() and a[:] for i in a[
Wolfgang Maier wrote:
> Dear all, with
> a=list(range(1,11))
>
> why (in Python 2.7 and 3.3) is this explicit for loop working:
> for i in a[:-1]:
> a.pop() and a
>
> giving:
> [1, 2, 3, 4, 5, 6, 7, 8, 9]
> [1, 2, 3, 4, 5, 6, 7, 8]
> [1, 2, 3, 4, 5, 6, 7]
> [1, 2, 3, 4, 5, 6]
> [1, 2, 3, 4,
Tim Chase tim.thechases.com> writes:
> it's because you're taking a snapshot copy of "a" in the middle of
> the loop. In your first example, if you change it to
>
> results = []
> for i in a[:-1]:
> results.append(a.pop() and a)
> print results
>
> you get the same thing as your list
On 28/03/13 15:25, Wolfgang Maier wrote:
Dear all, with
a=list(range(1,11))
why (in Python 2.7 and 3.3) is this explicit for loop working:
for i in a[:-1]:
a.pop() and a
giving:
[1, 2, 3, 4, 5, 6, 7, 8, 9]
[1, 2, 3, 4, 5, 6, 7, 8]
[1, 2, 3, 4, 5, 6, 7]
[1, 2, 3, 4, 5, 6]
[1, 2, 3, 4, 5]
[1