from itertools import takewhile sum takewhile lambda reversed

1
2
3
4
5
from itertools import takewhile
l = [1,3,4,0,5,6]
sum(takewhile(lambda x: x != 0, reversed(l)))