Question: Accesses the data stored in the file_data instance variable (a list) and converts it to a dictionary, data_dict, where each key is a column name

Accesses the data stored in the file_data instance variable (a list) and converts it to a dictionary, data_dict, where each key is a column name found in the CSV, and each value is a list of data in that column with the same order as it was in the file. Each element of the list corresponds to a single row in the CSV. For example, to access the Title column in the CSV, I would access data_dict[Title].Accesses the data stored in the file_data instance variable (a list) and^^^ this is the csv filed.

This is the code I have now (IN PYTHON). My error is that the list index is out of range and I have tried many things and not get how to fix this issue. The cvs has already been opened and read before this.

self.data_dict = {

'Title': [],

'Pages': [],

'URL': [],

'Author Name': [],

'Genre': [],

}

for i in range(len(self.file_data) + 1):

self.data_dict['Title'].append([i][0])

self.data_dict['Pages'].append([i][1])

self.data_dict['URL'].append([i][2])

self.data_dict['Author Name'].append([i][3])

self.data_dict['Genre'].append([i][-1])

1 2 3 4 5 6 7 8 9 10 11 12 13 Title, Pages, URL, Author Name, Genre The Book Thief,552, https://www.goodreads.com/book/show/19063, Markus Zusak, Historical Fiction The Hunger Games,374, https://www.goodreads.com/book/show/2767052, Suzanne Collins, Science Fiction Romeo and Juliet, 301, https://www.goodreads.com/book/show/18135, William Shakespeare, Romance To Kill a Mockingbird, 324, https://www.goodreads.com/book/show/2657, Harper Lee, Historical Fiction Pride and Prejudice, 279, https://www.goodreads.com/book/show/1885, Jane Austen, Historical Fiction Twilight, 501, https://www.goodreads.com/book/show/41865, Stephenie Meyer, Fantasy Animal Farm, 141, https://www.goodreads.com/book/show/170448, George Orwell, Science Fiction The Chronicles of Narnia, 767, https://www.goodreads.com/book/show/11127,C.S. Lewis, Fantasy The Fault in Our Stars, 313, https://www.goodreads.com/book/show/11870085, John Green, Romance Gone with the Wind, 1037, https://www.goodreads.com/book/show/18405, Margaret Mitchell, Historical Fiction The Alchemist, 182, https://www.goodreads.com/book/show/18144590, Paulo Coelho, Philosophy The Da Vinci Code, 489, https://www.goodreads.com/book/show/968, Dan Brown, Mystery Thriller The Picture of Dorian Gray, 272, https://www.goodreads.com/book/show/5297, Oscar Wilde, Horror Memoirs of a Geisha,503, https://www.goodreads.com/book/show/929, Arthur Golden, Historical Fiction Fahrenheit 451,194, https://www.goodreads.com/book/show/13079982, Ray Bradbury, Science Fiction Lord of the Flies, 182, https://www.goodreads.com/book/show/7624, William Golding, Science Fiction 14 15 16 17

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!