查找字符串中的数字,然后使用列表推导求和[仅1-9求和]

时间:2018-06-29 14:54:32

标签: python string python-3.x list sum

>>> 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

我想做列表理解中的总和

谢谢

0 个答案:

没有答案