Can I do this with list comprehension?

Gabriel Genellina gagsl-py at yahoo.com.ar
Wed Aug 23 00:37:50 EDT 2006


At Wednesday 23/8/2006 01:07, barberomarcelo at gmail.com wrote:

>a = [0, 1, 0, 1, 1, 0]
>b = [2, 4, 6, 8, 10, 12]
>
>I want a list comprehension that has the elements in b where a[element]
>== 1.
>
>That's to say, in the example above, the result must be: [4, 8, 10]

print [belem for aelem,belem in zip(a,b) if aelem==1]
print [belem for i,belem in enumerate(b) if a[i]==1]

Or itertools.izip...


Gabriel Genellina
Softlab SRL 


	
	
		
__________________________________________________
Preguntá. Respondé. Descubrí.
Todo lo que querías saber, y lo que ni imaginabas,
está en Yahoo! Respuestas (Beta).
¡Probalo ya! 
http://www.yahoo.com.ar/respuestas




More information about the Python-list mailing list