计算满足Python条件的所有条件

Oll*_*lie 1 python loops

有没有办法在速记嵌套循环中添加满足条件的所有内容?我的以下尝试未成功:

count += 1 if n == fresh for n in buckets['actual'][e] else 0
Run Code Online (Sandbox Code Playgroud)

Ash*_*ary 5

使用sum与发电机的表达:

sum(n == fresh for n in buckets['actual'][e])
Run Code Online (Sandbox Code Playgroud)

True == 1False == 0,因此else是不需要的.


相关读物:使用bool作为int是Pythonic吗? ,Python中的False == 0和True == 1是一个实现细节,还是由语言保证?