I am trying to write an if
statement in Python 3:
if n % 2 == 0:
list.append(2)
elif n % 3 == 0:
list.append(3)
elif n % 5 == 0:
list.append(5)
Is there a more space conservative way of doing this? I thought about using lambda expressions, but these bits of code don't seem to work.
if (lambda i: n % i == 0)(i in [2,3,5])
list.append(i)
and
if (lambda i: n % i == 0)([2,3,5])
list.append(i)
Is there a way to do this using lambda expressions? Or do I need a different approach? Also, if I use lambda expressions, will I be able to use the value of i for which the condition matches (like appending it to a list)?