Skip to content

Instantly share code, notes, and snippets.

@christophergregory
Last active August 29, 2015 14:05
Show Gist options
  • Save christophergregory/663c9585fb44c466e969 to your computer and use it in GitHub Desktop.
Save christophergregory/663c9585fb44c466e969 to your computer and use it in GitHub Desktop.
Class Assignment 3
Name,Number
Amal Albertson,7/2/1972
Sondra Shoemaker,2/2/1964
Ryann Ralphs,5/22/1999
Delcie Demma,8/19/1975
Gemma Gates,5/16/1999
Su Scurlock,3/18/1990
Delma Duchene,12/16/1994
Kathyrn Kreps,2/25/1965
Cinda Christon,6/26/1987
Lizette Lundgreen,2/15/1960
Era Everitt,9/1/1994
Hazel Heath,3/6/1978
Adan Alloway,6/4/1987
Bobbi Bunnell,2/5/1970
Dori Drolet,10/21/1979
Jeanett Jewett,1/23/1962
Nakita Niswonger,9/15/1973
Tonya Tillman,3/11/1997
Belia Backstrom,2/13/1986
Brant Beaudry,8/20/1982
Malvina Mattos,4/24/1988
Barrett Bateman,12/6/1978
Glennie Gutter,2/4/2000
Marlin Mizelle,4/22/1961
Leigh Leite,7/8/1970
Vada Vale,4/20/1991
Johnnie Jelinek,4/4/1966
Aurore Appleby,12/7/1991
Hallie Hadlock,7/27/1980
Sheri Sprung,1/21/1974
Stephany Stamp,1/6/1980
Madlyn Mulhern,9/12/1961
Lisette Lan,11/25/1989
Jenell Johansen,11/23/1983
Junko Jaquith,3/2/1974
Jenni Jenks,1/13/2000
Fernando Forck,1/4/1998
Elisabeth Ewan,9/18/1966
Emerita Ewen,10/8/1994
Eli Eisenman,8/25/1996
Malka Macaulay,8/4/1995
Emilie Ewell,10/8/1968
Lisabeth Lambdin,4/28/1981
Cayla Cassity,4/1/1994
Danyelle Doom,8/20/1978
Randy Rehman,2/19/1976
Laura Lipari,10/16/2000
Shemeka Sin,11/25/1973
Claire Cassidy,7/5/1964
Loise Lennon,6/5/1995
"""
Similar to assignment 2, you are now tasked with pulling data from
from multiple files and consolidating them into one CSV file. The
difference this time is that there are two files that contain two
different pieces of information for each person. The issue is that
the names of the people are not in the same order.
Your task is to read in the information from both files, figure out
a way to get them in the same order and print them to one CSV file
where the result will look something like this
Amal Albertson,7/2/1972,555.155.759
This can be accomplished with clever use of lists and for loops but
I want you to use what we learned about dictionaries to accomplish this.
Instead of reading each file into a list, try reading them into a dictionary
so that you can extract the data for the correct name once needed.
"""
# here is some code to get you started,
# this code reads in one of the files and
# adds the data to a dictionary
people = {}
with open('numbers.txt', 'r') as numbers:
for line in numbers:
data = line.rstrip().split(',')
people.update({ data[0] : data[1] })
print people
# You will need to do the same for the birthday file
# once you have both dictionaries you'll need to figure
# out a way to get print the data in the correct order
# to a new CSV file.
Name,Number
Dori Drolet,555.573.176
Aurore Appleby,555.977.786
Sondra Shoemaker,555.655.724
Nakita Niswonger,555.570.496
Jeanett Jewett,555.574.225
Eli Eisenman,555.529.419
Danyelle Doom,555.616.102
Jenni Jenks,555.734.797
Amal Albertson,555.155.759
Barrett Bateman,555.252.301
Junko Jaquith,555.627.258
Brant Beaudry,555.401.954
Delcie Demma,555.329.577
Bobbi Bunnell,555.519.686
Emilie Ewell,555.392.130
Marlin Mizelle,555.570.549
Kathyrn Kreps,555.375.276
Era Everitt,555.285.793
Jenell Johansen,555.190.483
Elisabeth Ewan,555.567.933
Vada Vale,555.484.802
Hazel Heath,555.516.655
Sheri Sprung,555.401.828
Tonya Tillman,555.883.209
Leigh Leite,555.861.370
Ryann Ralphs,555.101.375
Laura Lipari,555.381.560
Johnnie Jelinek,555.851.825
Randy Rehman,555.934.725
Fernando Forck,555.687.147
Cinda Christon,555.101.453
Lisabeth Lambdin,555.145.441
Shemeka Sin,555.166.179
Madlyn Mulhern,555.854.890
Claire Cassidy,555.542.416
Su Scurlock,555.262.868
Glennie Gutter,555.183.693
Lizette Lundgreen,555.289.891
Cayla Cassity,555.560.115
Adan Alloway,555.684.121
Delma Duchene,555.238.815
Loise Lennon,555.146.670
Gemma Gates,555.841.760
Belia Backstrom,555.729.716
Stephany Stamp,555.202.236
Malvina Mattos,555.131.636
Malka Macaulay,555.529.915
Emerita Ewen,555.736.232
Hallie Hadlock,555.470.368
Lisette Lan,555.678.651
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment