python - Adding strings as integers from two lists -
i have 2 lists. example,
list1 = ["7","3","19","5"] list2 = ["3","15,"13","16"] i want add these numbers 4 numbers. example result of 7+3 , 3+15.
my output overall should be
["10","18","32","21"] i've tried using loop instead of getting 7+3 = 10 7+3 = 73. have tried using int() method error.
use zip, int, , str inside list comprehension.
[str(int(x) + int(y)) x, y in zip(list1, list2)] result:
['10', '18', '32', '21']
Comments
Post a Comment