How to sum the integers from a list of strings and integers in Python

1 Answer

0 votes
lst = [1, 2, "a", 17, "b", 7, "c", "d"]

lsum = sum([int(i) for i in lst if type(i) == int or i.isdigit()])

print(lsum)




'''
run:

27

'''

 



answered Apr 16, 2021 by avibootz
edited Apr 16, 2021 by avibootz

Related questions

1 answer 204 views
2 answers 206 views
1 answer 150 views
2 answers 139 views
1 answer 105 views
...