+ 2

How can I get the sum of items in an itarator. That is after removing all even numbers in a list and itarating it.Someone help👋

p=[2,5,6,4 ,3,7] for i in p: if i%2==0: i.remove(i%2==o) print(sum(i)) print(sum(p))

23rd Feb 2021, 4:45 AM
Emmanuel Kipngeno cheruiyot
Emmanuel Kipngeno cheruiyot - avatar
3 RĂ©ponses
+ 3
p = [2,5,6,4,3,7] print(sum(x for x in p if x%2))
23rd Feb 2021, 5:36 AM
visph
visph - avatar
0
Visph thanks so much I appreciate
23rd Feb 2021, 7:04 AM
Emmanuel Kipngeno cheruiyot
Emmanuel Kipngeno cheruiyot - avatar
0
List comprehension is best for solving suchđŸ€—đŸ€—
23rd Feb 2021, 7:05 AM
Emmanuel Kipngeno cheruiyot
Emmanuel Kipngeno cheruiyot - avatar