About a list comprehension to transform an input list

2012-06-08 Thread Julio Sergio
From a sequence of numbers, I'm trying to get a list that does something to even numbers but leaves untouched the odd ones, say: [0,1,2,3,4,...] == [100,1,102,3,104,...] I know that this can be done with an auxiliary function, as follows: - def filter(n): ... if (n%2 == 0): ...

Re: About a list comprehension to transform an input list

2012-06-08 Thread Daniel Urban
On Fri, Jun 8, 2012 at 6:10 PM, Julio Sergio julioser...@gmail.com wrote: From a sequence of numbers, I'm trying to get a list that does something to even numbers but leaves untouched the odd ones, say: [0,1,2,3,4,...] == [100,1,102,3,104,...] I know that this can be done with an auxiliary

Re: About a list comprehension to transform an input list

2012-06-08 Thread Emile van Sebille
On 6/8/2012 9:17 AM Daniel Urban said... On Fri, Jun 8, 2012 at 6:10 PM, Julio Sergiojulioser...@gmail.com wrote: From a sequence of numbers, I'm trying to get a list that does something to even numbers but leaves untouched the odd ones, say: [0,1,2,3,4,...] == [100,1,102,3,104,...] I

Re: About a list comprehension to transform an input list

2012-06-08 Thread Ian Kelly
On Fri, Jun 8, 2012 at 10:43 AM, Emile van Sebille em...@fenx.com wrote: Or alternately by leveraging true/false as 1/0: [ 100*(not(ii%2))+ii for ii in range(10)] The same thing, leaving bools out of it altogether: [100*(1-ii%2)+ii for ii in range(10)] --