0%

Python列表推导式中if else判断

if

1
[fun(item) for item in list if condition]

if else

1
[fun1(item) if condition else fun2(item) for item in list]

if else if

1
[fun1(item) if condition1 else fun2(item) if condition2 fun3(item) else fun4(item) for item in list]