Removing all commas from list in Python

后端 未结 7 888
旧巷少年郎
旧巷少年郎 2021-01-07 12:26

My issue: I\'d like to add all the digits in this string \'1.14,2.14,3.14,4.14\' but the commas are causing my sum function to not work correctly.
I figured

相关标签:
7条回答
  • 2021-01-07 13:24

    This will add all of the digits in the first string in your question:

    sum(float(x) for x in '1.14,2.14,3.14,4.14' if x.isdigit())
    
    0 讨论(0)
提交回复
热议问题