Can I do this with list comprehension?

barberomarcelo at gmail.com barberomarcelo at gmail.com
Wed Aug 23 00:07:36 EDT 2006


Let's say I have two lists:

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]

Any hints?

Marcelo




More information about the Python-list mailing list