+ 5
How to add numbers in a string(such as:- abc123 which gives result as 6)?
2 Answers
+ 4
A little late, but here is my try:
a = 'a1b2c3d4'
print(sum([int(i) for i in a if i.isdigit()]))
# or in a for loop:
x = 0
for i in a:
if i.isdigit():
x += int(i)
print(x)
+ 2
Thanks