list comprehension example
Posted
by
self
on Stack Overflow
See other posts from Stack Overflow
or by self
Published on 2012-04-03T05:16:30Z
Indexed on
2012/04/03
5:29 UTC
Read the original article
Hit count: 233
can we use elif in list comprehension?
example :
l = [1, 2, 3, 4, 5]
for values in l:
if values==1:
print 'yes'
elif values==2:
print 'no'
else:
print 'idle'
can we use list comprehension for such 2 if conditions and one else condition?
foe example answer like :
['yes', 'no', 'idle', 'idle', 'idle']
I have done till now only if else in list comprehension.
© Stack Overflow or respective owner