partb2 complete
This commit is contained in:
parent
1c39aa1873
commit
cf9299e503
1 changed files with 20 additions and 3 deletions
23
partb2.py
23
partb2.py
|
@ -1,5 +1,22 @@
|
||||||
# Part B Task 2
|
|
||||||
import re
|
import re
|
||||||
import os
|
import argparse
|
||||||
import sys
|
|
||||||
|
|
||||||
|
# parse input arguments
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('path_to_file', help = 'path to the csv file')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# open file, add all lines to a single string
|
||||||
|
file_given = open(args.path_to_file)
|
||||||
|
f = ""
|
||||||
|
for line in file_given:
|
||||||
|
f += line + " "
|
||||||
|
file_given.close()
|
||||||
|
|
||||||
|
# remove non-alphabetic characters, replace all whitespace characters with a
|
||||||
|
# single whitespace, and change all uppercase characters to lowercase
|
||||||
|
f = re.sub(r'[^a-zA-Z\s]', r'', f)
|
||||||
|
f = re.sub(r'\s+', r' ', f)
|
||||||
|
f = f.lower()
|
||||||
|
|
||||||
|
print(f)
|
||||||
|
|
Loading…
Reference in a new issue