I have a function that takes a CSV file and splits it into 3 values; isbn
, author
and title
then creates a dictionary that maps isbn
values to tuples containing the author
and title
. This is my current code:
def isbn_dictionary(filename):
file = open(filename, 'r')
for line in file:
data = line.strip('\n')
author, title, isbn = data.split(',')
isbn_dict = {isbn:(author, title)}
print(isbn_dict)
The problem is that at the moment I can get it to create a dictionary for each isbn
but not one for all of them. My current output is:
{'0-586-08997-7': ('Kurt Vonnegut', 'Breakfast of Champions')}
{'978-0-14-302089-9': ('Lloyd Jones', 'Mister Pip')}
{'1-877270-02-4': ('Joe Bennett', 'So Help me Dog')}
{'0-812-55075-7': ('Orson Scott Card', 'Speaker for the Dead')}
What my output should be:
{'0-586-08997-7': ('Kurt Vonnegut', 'Breakfast of Champions'),
'978-0-14-302089-9': ('Lloyd Jones', 'Mister Pip'),
'1-877270-02-4': ('Joe Bennett', 'So Help me Dog'),
'0-812-55075-7': ('Orson Scott Card', 'Speaker for the Dead')}
It's probably a really simple issue but I cannot get my head around it.