列表推导式多个条件判断if else in a list com
2017-12-05 本文已影响0人
阴天有时下肉丸
if else in a list comprehension
l = [22, 13, 45, 50, 98, 69, 43, 44, 1]
[x+1 if x >= 45 else x+5 for x in l]
[27, 18, 46, 51, 99, 70, 48, 49, 6]
Do-something if <condition>, else do-something else.