Re: GOTCHA with list comprehension

2015-08-07 Thread Saran Ahluwalia
@ChrisA You, my friend, certainly put the nail in the coffin! Sent from my iPhone On Aug 5, 2015, at 5:52 AM, Chris Angelico ros...@gmail.com wrote: On Wed, Aug 5, 2015 at 7:01 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: You can chain 'for' and 'if' clauses

GOTCHA with list comprehension

2015-08-05 Thread Pavel S
Hi, I recently found interesting GOTCHA while doing list comprehension in python 2.6: values = ( True, False, 1, 2, 3, None ) [ value for value in values if value if not None ] [True, 1, 2, 3] I was wondering why this list comprehension returns incorrect results and finally found a typo

Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
(a): Hi, I recently found interesting GOTCHA while doing list comprehension in python 2.6: values = ( True, False, 1, 2, 3, None ) [ value for value in values if value if not None ] [True, 1, 2, 3] I was wondering why this list comprehension returns incorrect results and finally found

Re: GOTCHA with list comprehension

2015-08-05 Thread Chris Angelico
On Wed, Aug 5, 2015 at 4:48 PM, Pavel S pa...@schon.cz wrote: Hi, I recently found interesting GOTCHA while doing list comprehension in python 2.6: values = ( True, False, 1, 2, 3, None ) [ value for value in values if value if not None ] [True, 1, 2, 3] I was wondering why this list

Re: GOTCHA with list comprehension

2015-08-05 Thread Peter Otten
Pavel S wrote: Hi, I recently found interesting GOTCHA while doing list comprehension in python 2.6: values = ( True, False, 1, 2, 3, None ) [ value for value in values if value if not None ] [True, 1, 2, 3] I was wondering why this list comprehension returns incorrect results

Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
$ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (Santiago) $ python --version Python 2.6.6 Incidentally, why Python 2.6? ChrisA -- https://mail.python.org/mailman/listinfo/python-list

Re: GOTCHA with list comprehension

2015-08-05 Thread Chris Angelico
On Wed, Aug 5, 2015 at 5:03 PM, Pavel S pa...@schon.cz wrote: It seems this is allowed by the grammar: list_display::= [ [expression_list | list_comprehension] ] list_comprehension ::= expression list_for list_for::= for target_list in old_expression_list [list_iter]

Re: GOTCHA with list comprehension

2015-08-05 Thread Chris Angelico
On Wed, Aug 5, 2015 at 5:10 PM, Pavel S pa...@schon.cz wrote: $ cat /etc/redhat-release Red Hat Enterprise Linux Server release 6.5 (Santiago) $ python --version Python 2.6.6 Incidentally, why Python 2.6? I guess that would be why :) That's probably actually a patched 2.6.6 - from what I

Re: GOTCHA with list comprehension

2015-08-05 Thread Pavel S
Hi Chris, yeah, I have to stick on the software which my employer provides to me (we're enterprise company). I'm not root on that system. I'm happy with 2.6 now, two years ago we were on older RHEL with python 2.4 and it was a real pain :) $ cat /etc/redhat-release Red Hat Enterprise Linux

Re: GOTCHA with list comprehension

2015-08-05 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: You can chain 'for' and 'if' clauses as much as you like, and they behave exactly the way you'd expect. How do you know what I'd expect? I wouldn't know what to expect myself. Marko -- https://mail.python.org/mailman/listinfo/python-list

Re: GOTCHA with list comprehension

2015-08-05 Thread Chris Angelico
On Wed, Aug 5, 2015 at 7:01 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: You can chain 'for' and 'if' clauses as much as you like, and they behave exactly the way you'd expect. How do you know what I'd expect? I wouldn't know what to expect myself. A list

Re: GOTCHA with list comprehension

2015-08-05 Thread Marko Rauhamaa
Chris Angelico ros...@gmail.com: On Wed, Aug 5, 2015 at 7:01 PM, Marko Rauhamaa ma...@pacujo.net wrote: Chris Angelico ros...@gmail.com: You can chain 'for' and 'if' clauses as much as you like, and they behave exactly the way you'd expect. How do you know what I'd expect? I wouldn't

Re: GOTCHA with list comprehension

2015-08-05 Thread Laura Creighton
In a message of Wed, 05 Aug 2015 17:05:49 +1000, Chris Angelico writes: Incidentally, why Python 2.6? Python 2.7 has been out for a pretty long time now, and if you can't move to version 3.x, I would at least recommend using 2.7. Since the release of 2.6.9 back before Frozen came out, that branch

Re: GOTCHA with list comprehension

2015-08-05 Thread Chris Angelico
On Thu, Aug 6, 2015 at 2:39 PM, Laura Creighton l...@openend.se wrote: In a message of Wed, 05 Aug 2015 17:05:49 +1000, Chris Angelico writes: Incidentally, why Python 2.6? Python 2.7 has been out for a pretty long time now, and if you can't move to version 3.x, I would at least recommend using