Tips: Since True == 1, sum() can count Trues. >>> def count_even(seq): ... return sum(i%2 == 0 for i in seq)
>>> count_even(range(100)) 50 -- https://mail.python.org/mailman/listinfo/python-list
Tips: Since True == 1, sum() can count Trues. >>> def count_even(seq): ... return sum(i%2 == 0 for i in seq)
>>> count_even(range(100)) 50 -- https://mail.python.org/mailman/listinfo/python-list