I was wondering, is it possible to put multiple if conditions in a list comprehension? I didn\'t find anything like this in the docs.
if
I want to be able
You can put you logic in a separate function, and then have the elegance of the list comprehension along with the readability of the function:
def cond(i): if i % 4 == 0: return 'four' elif i % 6 == 0: return 'six' return i l=[cond(i) for i in range(1,n)]