I'm trying to convert one list to another by applying a condition on the list's elements. But I can't figure out how to do this in mathematica's language. Python example below
l1 = [0, 1, 2, 3, 4]
l2 = []
for i in l1:
if i % 2 == 0:
l2.append(i)
else:
l2.append(0)
{0, 1, 2, 3, 4} // Select[Mod[#, 2] == 0 &] (* {0, 2, 4} *)
$\endgroup$ – alancalvitti Nov 25 '14 at 17:06