Skip to content

Instantly share code, notes, and snippets.

@MichelleDalalJian
Created October 7, 2017 14:48
Show Gist options
  • Select an option

  • Save MichelleDalalJian/4d630b054e647b2d61a5ed9bcc385f10 to your computer and use it in GitHub Desktop.

Select an option

Save MichelleDalalJian/4d630b054e647b2d61a5ed9bcc385f10 to your computer and use it in GitHub Desktop.
Extracting Data With Regular Expressions Finding Numbers in a Haystack In this assignment you will read through and parse a file with text and numbers. You will extract all the numbers in the file and compute the sum of the numbers. Data Files We provide two files for this assignment. One is a sample file where we give you the sum for your testi…
import re
hand = open("regex_sum_24962.txt")
x=list()
for line in hand:
y = re.findall('[0-9]+',line)
x = x+y
sum=0
for z in x:
sum = sum + int(z)
print(sum)
@rim12345615

Copy link
Copy Markdown

Actual data: http://py4e-data.dr-chuck.net/regex_sum_2371597.txt (There are 82 values and the sum ends with 487
sum end with 487
i need help with this.

@LeDonBobo

Copy link
Copy Markdown

Actual data: http://py4e-data.dr-chuck.net/regex_sum_2371597.txt (There are 82 values and the sum ends with 487 sum end with 487 i need help with this.

You can copy paste my program and replace "Your_file_name" by your URL, it should work.
Ps: don't forget to indent correctly ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment