Skip to content

Instantly share code, notes, and snippets.

@AreebaYousuf
AreebaYousuf / gist:709f45072514cc2ae13eb7be0d45e5f0
Created April 7, 2023 19:37
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 testing and the other is the actual data you n…
import re
fh=open('week_1.txt')
l=list()
for digits in fh:
digits=digits.rstrip()
stuff=re.findall('[0-9]+',digits)
if len(stuff)>0:
l=l+stuff
sum=0
for n in l: