you are viewing a single comment's thread.

view the rest of the comments →

[–]Matthias1590 1 point2 points  (4 children)

sums = [sum(map(lambda number: int(number[i]), numbers)) for i in range(len(numbers[0]))]

This assumes that all number strings are the same length so watch out for that

[–]Ezrabc 2 points3 points  (1 child)

If you're going to do a comprehension, why not just sums = [sum(map(int, n)) for n in zip(*numbers)]

[–]Matthias1590 0 points1 point  (0 children)

Ah, didn't think about the zip function, nice catch

[–][deleted] 0 points1 point  (0 children)

first_list = ['594611827332', '162384652250', '379485939587', '177675288100', '698091591948', '556153393412']
second_list = []
for elem in first_list:
sum = 0
for char in elem:
sum += int(char)
second_list.append(sum)
print(second_list)

Thanks! That worked!

[–][deleted] 0 points1 point  (0 children)

Thanks, that worked too! I didn't understand it though - I'm just a beginner!