Home > Software design >  how to calculate sum of numbers in a string of list using python [closed]
how to calculate sum of numbers in a string of list using python [closed]

Time:09-23

how to calculate sum of numbers in a string of list using python l=['1000', '1000', '100', '30' ,'30,1,9' ] output should be l=['1000', '1000', '100', '30', '40'] how to do it using python

CodePudding user response:

>>> data = ['1000', '1000', '100', '30' ,'30,1,9' ]
>>> [str(sum(map(int, item.split(',')))) for item in data]
['1000', '1000', '100', '30', '40']
  • Related