Preparing git repo for final project
This commit is contained in:
54
problems/pset6/scourgify/after.csv
Normal file
54
problems/pset6/scourgify/after.csv
Normal file
@@ -0,0 +1,54 @@
|
||||
first,last,house
|
||||
Hannah,Abbott,Hufflepuff
|
||||
Katie,Bell,Gryffindor
|
||||
Susan,Bones,Hufflepuff
|
||||
Terry,Boot,Ravenclaw
|
||||
Lavender,Brown,Gryffindor
|
||||
Millicent,Bulstrode,Slytherin
|
||||
Cho,Chang,Ravenclaw
|
||||
Penelope,Clearwater,Ravenclaw
|
||||
Vincent,Crabbe,Slytherin
|
||||
Colin,Creevey,Gryffindor
|
||||
Dennis,Creevey,Gryffindor
|
||||
Cedric,Diggory,Hufflepuff
|
||||
Marietta,Edgecombe,Ravenclaw
|
||||
Justin,Finch-Fletchley,Hufflepuff
|
||||
Seamus,Finnigan,Gryffindor
|
||||
Anthony,Goldstein,Ravenclaw
|
||||
Gregory,Goyle,Slytherin
|
||||
Hermione,Granger,Gryffindor
|
||||
Angelina,Johnson,Gryffindor
|
||||
Lee,Jordan,Gryffindor
|
||||
Neville,Longbottom,Gryffindor
|
||||
Luna,Lovegood,Ravenclaw
|
||||
Remus,Lupin,Gryffindor
|
||||
Draco,Malfoy,Slytherin
|
||||
Scorpius,Malfoy,Slytherin
|
||||
Ernie,Macmillan,Hufflepuff
|
||||
Minerva,McGonagall,Gryffindor
|
||||
Eloise,Midgen,Gryffindor
|
||||
Cormac,McLaggen,Gryffindor
|
||||
Graham,Montague,Slytherin
|
||||
Theodore,Nott,Slytherin
|
||||
Pansy,Parkinson,Slytherin
|
||||
Padma,Patil,Gryffindor
|
||||
Parvati,Patil,Gryffindor
|
||||
Harry,Potter,Gryffindor
|
||||
Tom,Riddle,Slytherin
|
||||
Demelza,Robins,Gryffindor
|
||||
Newt,Scamander,Hufflepuff
|
||||
Horace,Slughorn,Slytherin
|
||||
Zacharias,Smith,Hufflepuff
|
||||
Severus,Snape,Slytherin
|
||||
Alicia,Spinnet,Gryffindor
|
||||
Pomona,Sprout,Hufflepuff
|
||||
Dean,Thomas,Gryffindor
|
||||
Romilda,Vane,Gryffindor
|
||||
Myrtle,Warren,Ravenclaw
|
||||
Fred,Weasley,Gryffindor
|
||||
George,Weasley,Gryffindor
|
||||
Ginny,Weasley,Gryffindor
|
||||
Percy,Weasley,Gryffindor
|
||||
Ron,Weasley,Gryffindor
|
||||
Oliver,Wood,Gryffindor
|
||||
Blaise,Zabini,Slytherin
|
|
54
problems/pset6/scourgify/before.csv
Normal file
54
problems/pset6/scourgify/before.csv
Normal file
@@ -0,0 +1,54 @@
|
||||
name,house
|
||||
"Abbott, Hannah",Hufflepuff
|
||||
"Bell, Katie",Gryffindor
|
||||
"Bones, Susan",Hufflepuff
|
||||
"Boot, Terry",Ravenclaw
|
||||
"Brown, Lavender",Gryffindor
|
||||
"Bulstrode, Millicent",Slytherin
|
||||
"Chang, Cho",Ravenclaw
|
||||
"Clearwater, Penelope",Ravenclaw
|
||||
"Crabbe, Vincent",Slytherin
|
||||
"Creevey, Colin",Gryffindor
|
||||
"Creevey, Dennis",Gryffindor
|
||||
"Diggory, Cedric",Hufflepuff
|
||||
"Edgecombe, Marietta",Ravenclaw
|
||||
"Finch-Fletchley, Justin",Hufflepuff
|
||||
"Finnigan, Seamus",Gryffindor
|
||||
"Goldstein, Anthony",Ravenclaw
|
||||
"Goyle, Gregory",Slytherin
|
||||
"Granger, Hermione",Gryffindor
|
||||
"Johnson, Angelina",Gryffindor
|
||||
"Jordan, Lee",Gryffindor
|
||||
"Longbottom, Neville",Gryffindor
|
||||
"Lovegood, Luna",Ravenclaw
|
||||
"Lupin, Remus",Gryffindor
|
||||
"Malfoy, Draco",Slytherin
|
||||
"Malfoy, Scorpius",Slytherin
|
||||
"Macmillan, Ernie",Hufflepuff
|
||||
"McGonagall, Minerva",Gryffindor
|
||||
"Midgen, Eloise",Gryffindor
|
||||
"McLaggen, Cormac",Gryffindor
|
||||
"Montague, Graham",Slytherin
|
||||
"Nott, Theodore",Slytherin
|
||||
"Parkinson, Pansy",Slytherin
|
||||
"Patil, Padma",Gryffindor
|
||||
"Patil, Parvati",Gryffindor
|
||||
"Potter, Harry",Gryffindor
|
||||
"Riddle, Tom",Slytherin
|
||||
"Robins, Demelza",Gryffindor
|
||||
"Scamander, Newt",Hufflepuff
|
||||
"Slughorn, Horace",Slytherin
|
||||
"Smith, Zacharias",Hufflepuff
|
||||
"Snape, Severus",Slytherin
|
||||
"Spinnet, Alicia",Gryffindor
|
||||
"Sprout, Pomona",Hufflepuff
|
||||
"Thomas, Dean",Gryffindor
|
||||
"Vane, Romilda",Gryffindor
|
||||
"Warren, Myrtle",Ravenclaw
|
||||
"Weasley, Fred",Gryffindor
|
||||
"Weasley, George",Gryffindor
|
||||
"Weasley, Ginny",Gryffindor
|
||||
"Weasley, Percy",Gryffindor
|
||||
"Weasley, Ron",Gryffindor
|
||||
"Wood, Oliver",Gryffindor
|
||||
"Zabini, Blaise",Slytherin
|
|
7
problems/pset6/scourgify/in.csv
Normal file
7
problems/pset6/scourgify/in.csv
Normal file
@@ -0,0 +1,7 @@
|
||||
name,house
|
||||
"Abbott, Hannah",Hufflepuff
|
||||
"Bell, Katie",Gryffindor
|
||||
"Bones, Susan",Hufflepuff
|
||||
"Boot, Terry",Ravenclaw
|
||||
"Brown, Lavender",Gryffindor
|
||||
"Bulstrode, Millicent",Slytherin
|
|
5
problems/pset6/scourgify/out.csv
Normal file
5
problems/pset6/scourgify/out.csv
Normal file
@@ -0,0 +1,5 @@
|
||||
first,last,house
|
||||
Susan,Bones,Hufflepuff
|
||||
Terry,Boot,Ravenclaw
|
||||
Lavender,Brown,Gryffindor
|
||||
Millicent,Bulstrode,Slytherin
|
|
42
problems/pset6/scourgify/scourgify.py
Normal file
42
problems/pset6/scourgify/scourgify.py
Normal file
@@ -0,0 +1,42 @@
|
||||
import csv
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main():
|
||||
try:
|
||||
input_file_name, output_file_name = sys.argv[1:3]
|
||||
except IndexError:
|
||||
print("Too few command-line arguments")
|
||||
sys.exit(1)
|
||||
if len(sys.argv) > 3:
|
||||
print("Too many command-line arguments")
|
||||
sys.exit(1)
|
||||
if not os.path.isfile(input_file_name): # Or try opening and catch FileNotFoundError
|
||||
print(f"Could not read {input_file_name}")
|
||||
sys.exit(1)
|
||||
if not input_file_name.endswith('.csv'):
|
||||
print(f"Not a CSV file")
|
||||
sys.exit(1)
|
||||
write_names_to_csv_file(read_names_from_csv_file(input_file_name), output_file_name)
|
||||
|
||||
|
||||
def read_names_from_csv_file(input_file_name):
|
||||
with open(input_file_name, 'r') as input_file:
|
||||
reader = csv.DictReader(input_file)
|
||||
for row in reader:
|
||||
yield row
|
||||
|
||||
|
||||
def write_names_to_csv_file(input_data, output_file_name):
|
||||
with open(output_file_name, 'w') as output_file:
|
||||
writer = csv.DictWriter(output_file, fieldnames=['first', 'last', 'house'])
|
||||
writer.writeheader()
|
||||
for row in input_data:
|
||||
row['last'], row['first'] = row['name'].split(', ')
|
||||
del row['name']
|
||||
writer.writerow(row)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Reference in New Issue
Block a user