扫码关注官方订阅号
类似于
d = [True for a in b if condition]
是否能单行实现
d = [True for a in b if condition else False]
这样的功能
直接 [condition for a in b]不就行了。。
[x==a for a in b]list(map(lambda x:x==a,b)
这个肯定满足
a_list = [1,2,3,4,5,6]
b = [True if i>3 else False for i in a_list]
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
直接 [condition for a in b]不就行了。。
[x==a for a in b]
list(map(lambda x:x==a,b)
这个肯定满足
a_list = [1,2,3,4,5,6]
b = [True if i>3 else False for i in a_list]