首页 > 开发 > Python > 正文

Python是否能实现单行[True for a in b if condition else False]这样的功能

2017-09-06 19:32:10  来源:网友分享

类似于

d = [True for a in b if condition]

是否能单行实现

d = [True for a in b if condition else False]

这样的功能

解决方案

直接 [condition for a in b]不就行了。。