Skip to content

Instantly share code, notes, and snippets.

View deleonab's full-sized avatar

Dele Onabowu deleonab

  • London
View GitHub Profile
@deleonab
deleonab / gist:326d41b8c62c7b18d1e8233752589d4d
Created March 21, 2022 07:31
11.2 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 …
import re
my_file = open('regex_sum_1511276.txt')
myreadfile = my_file.read()
myextractednums = re.findall('[0-9]+',myreadfile)
totalnums = 0
for mynum in myextractednums:
totalnums = totalnums + int(mynum)