Sum of strings extracted from text file using regex

后端 未结 8 1132
梦毁少年i
梦毁少年i 2020-12-10 19:47

I am just learning python and need some help for my class assignment.

I have a file with text and numbers in it. Some lines have from one to three numbers and other

8条回答
  •  执念已碎
    2020-12-10 20:40

    import re
    print sum([int(i) for i in re.findall('[0-9]+',open(raw_input('What is the file you want to analyze?\n'),'r').read())])
    

    You can compact it into one line, but this is only for fun!

提交回复
热议问题