Do comprehensions need to end with an else, if I am using else if?
examples:
a = ['tuple' if type(x)==tuple else 'int' if type(x)==int else 'float'
if type(x)==float for x in [1, 2.5, (5,6), {}]]
print(a)
It won't work and will make expected else after if expression
, but this will work:
a = ['tuple' if type(x)==tuple else 'int' if type(x)==int else 'float'
if type(x)==float else None for x in [1, 2.5, (5,6), {}]]
print(a)
output: ['int', 'float', 'tuple', None]
after all I don't want the None there.