I have a data file. It is a csv file. I have created a dictionary like this from it: {movie_id: ('title', ['genres']}. I want to know how to remove the empty strings that come about in the list of genres within the tuple within the dictionary
The data file(.csv) is like this:
movie_id title genres 68735 Warcraft Action Adventure Comedy 124057 Kids at the round table
def read_movies(movie_file: TextIO) -> MovieDict:
"""Return a dictionary containing movie id to (movie name, movie genres)
in the movie_file.
"""
line = movie_file.readline()
while line == '':
line = movie_file.readline()
reader = csv.reader(movie_file)
movie_dict = {int(rows[0]): (rows[1], rows[4:]) for rows in reader}
return movie_dict
I expect the output when movies_dict is called to be:
{68735: ('Warcraft', ['Action', 'Adventure', 'Fantasy']), 293660: ('Deadpool', ['Action', 'Adventure', 'Comedy']), 302156: ('Criminal', ['Action']), 124057: ('Kids of the Round Table', [])}
What I get with my code:
{68735: ('Warcraft', ['Action', 'Adventure', 'Fantasy']), 293660: ('Deadpool', ['Action', 'Adventure', 'Comedy']), 302156: ('Criminal', ['Action', '', '']), 124057: ('Kids of the Round Table', ['', '', ''])}