Extended List Comprehension

2006-01-20 Thread James Stroud
Would anyone else find this syntax useful for generator expressions? py [x for x in '1234' if x%2 else 'even'] [1, 'even', 3, 'even'] I'm guessing this has been suggested before? James -- http://mail.python.org/mailman/listinfo/python-list

Re: Extended List Comprehension

2006-01-20 Thread Paul Rubin
James Stroud [EMAIL PROTECTED] writes: py [x for x in '1234' if x%2 else 'even'] [1, 'even', 3, 'even'] I'm guessing this has been suggested before? You could (in 2.5) use: [(x if x%2 else 'even') for x in '1234'] -- http://mail.python.org/mailman/listinfo/python-list

Re: Extended List Comprehension

2006-01-20 Thread James Stroud
James Stroud wrote: Would anyone else find this syntax useful for generator expressions? py [x for x in '1234' if x%2 else 'even'] [1, 'even', 3, 'even'] I'm guessing this has been suggested before? James Before anyone notices, I should say: [x for x in [1,2,3,4] if x%2 else 'even']

Re: Extended List Comprehension

2006-01-20 Thread Tim Chase
py [x for x in '1234' if x%2 else 'even'] [1, 'even', 3, 'even'] I'm guessing this has been suggested before? You could (in 2.5) use: [(x if x%2 else 'even') for x in '1234'] This failed on multiple levels in 2.3.5 (the if syntax is unrecognized, and trying the below with '1234'

Re: Extended List Comprehension

2006-01-20 Thread Ido Yehieli
As Paul already demonstrated, this is hardly needed since it can be done more clearly with existing lang. features. -- http://mail.python.org/mailman/listinfo/python-list

Re: Extended List Comprehension

2006-01-20 Thread Joel Bender
You could (in 2.5) use: [(x if x%2 else 'even') for x in '1234'] Or this: [int(x)1 and x or 'even' for x in '1234'] -- http://mail.python.org/mailman/listinfo/python-list

Re: Extended List Comprehension

2006-01-20 Thread Paul Rubin
Tim Chase [EMAIL PROTECTED] writes: You could (in 2.5) use: [(x if x%2 else 'even') for x in '1234'] This failed on multiple levels in 2.3.5 (the if syntax is unrecognized, Yes, that syntax is new to 2.5. However, this worked in my 2.3.5: [((x%2 == 0 and 'even') or x) for x in