use isinstance
sum over iterator instead of list
removed trailing whitespace