Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Nicolas Borie
Le 28/06/2015 22:47, Anne Schilling a écrit : Hi Nicolas B., Thank you for your explanations! It was a little difficult to find this bug since in some cases it actually works {{{ sage: positions=[1,2,3,4,5,6] sage: for j in positions: if is_even(j): positions.remove(j) : sage:

Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Anne Schilling
Hi Nicolas B., Thank you for your explanations! It was a little difficult to find this bug since in some cases it actually works {{{ sage: positions=[1,2,3,4,5,6] sage: for j in positions: if is_even(j): positions.remove(j) : sage: positions [1, 3, 5] }}} {{{ sage: positions=[1,2,3

Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Travis Scrimshaw
I'm surprised it's not raising an error as well because I knew of the error that the dictionary raises that Simon mentioned having personally encountered it in my code myself. There is not a copy of i with its current value that build the current > lambda each step, no. In fact, all lambda use

Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Darij Grinberg
On Sun, Jun 28, 2015 at 12:05 PM, Nicolas Borie wrote: > i is a free variable and exist in a single piece of memory... Gods. This is worse than I thought... The only reason why this doesn't happen for, say, "L = [2**i for i in range(5)]", is that 2**i is eagerly evaluated, I guess? > What about

Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Nicolas Borie
Le 28/06/2015 11:42, Darij Grinberg a écrit : On Sun, Jun 28, 2015 at 10:07 AM, Nicolas Borie wrote: PS: The last entry of my collection of Python tricky codes was danger from free variables : (MAKE A LIST OF FIRST POWER FUNCTION (1, X, X^2, X^3, X^4)) L = [lambda x : x**i for i in range(5)]

Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Darij Grinberg
On Sun, Jun 28, 2015 at 10:07 AM, Nicolas Borie wrote: > PS: The last entry of my collection of Python tricky codes was danger from > free variables : (MAKE A LIST OF FIRST POWER FUNCTION (1, X, X^2, X^3, > X^4)) L = [lambda x : x**i for i in range(5)] # BAD [L[j](2) for j in range(5)]

Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Nicolas M. Thiery
On Sun, Jun 28, 2015 at 10:07:43AM +0200, Nicolas Borie wrote: > Le 28/06/2015 06:55, Anne Schilling a écrit : > >Is this what I should expect from this code: > > > >sage: positions=[1,2,3,4,5,6] > >sage: for j in positions: > >: positions.remove(j) > >: > >sage: positions > >[2, 4, 6]

Re: [sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-28 Thread Nicolas Borie
Le 28/06/2015 06:55, Anne Schilling a écrit : Hi! Is this what I should expect from this code: sage: positions=[1,2,3,4,5,6] sage: for j in positions: : positions.remove(j) : sage: positions [2, 4, 6] Wha this one will increase my collection of tricky examples... There is a war

[sage-combinat-devel] weird behavior under combining remove and for loop

2015-06-27 Thread Anne Schilling
Hi! Is this what I should expect from this code: sage: positions=[1,2,3,4,5,6] sage: for j in positions: : positions.remove(j) : sage: positions [2, 4, 6] Shouldn't I expect the empty list at the end? Of course, I agree the code is a little weird since it is running through a list wh