需要以下详细代码的一行代码

问题描述 投票:-2回答:1
a = [4, 5, 3, 6, 7, 8, 9]
count = 0
for i in a:
    if i == 1 or i == 2 or i == 3 or i == 4 or i == 5 or i == 0:
        count += I
print(count)

我尝试过以下一行代码,但是不起作用:

print(sum(i) if (i == 1 or i == 2 or i == 3 or i == 4 or i == 5 or i == 0) for i in a)
python string line inline
1个回答
0
投票
print(sum([x for x in a if x < 6]))
© www.soinside.com 2019 - 2024. All rights reserved.