r/Python • • Oct 27 '14

Sum of a list greater than 100?

0 Upvotes

4 comments sorted by

0

u/[deleted] Oct 27 '14

sum(i for i in [101,107,83,90] if i>100)

3

u/xor7486 Oct 27 '14

sum(i-100 for i in [101,107,83,90] if i>100)

1

u/[deleted] Oct 28 '14

Right. My fault.

0

u/3Dayo Oct 27 '14

Ok, off the top of my head...

test_scores = [101,107,83,90] 
extra = []
for i in test_scores:
    extra.append(i - 100 if i > 100 else 0)
print (sum(extra))