1
>>> a = "L2-L3"
>>> removeword = ["L","-"]
>>> add = [sum(int(j) for j in i) for i in a.strip() if i not in removeword]
>>> print(add)
[2, 3] # expected 5

I want to do the sum in list comprehension

Thanks

dimension
  • 982
  • 10
  • 18

0 Answers0