So I am trying to use the IMDBpy module to connect a list of programs to their respective Genres. First I am trying to get a new list of their IMDB IDs to, from there, get their corresponding Genre. Unfortunately I am unable to iterate through my list of programs and generate a new list of corresponding IDs. Somehow my function gets stuck at the first iteration. What am I missing in my definition?
from imdb import IMDB
ia = IMDb()
programs = ['midsomer murders', 'wheeler dealers: dream car', 'solo: a star wars story (2018)']
def ids_list(x):
ids = []
for item in list(x):
movie = ia.search_movie(item)[0].getID()
for movie in movies:
ids.append(movie)
return ids
ids_list(programs)
output:
['0118401']
As you can see only the first item comes through, whereas my code suggests it should append every item in the list after running it through ia.search_movie(item)[0].getID(). Thanks in advance!
return idsto out of theouter-for-loopn tryun-indentthereturnstatement onceia.search_movie(item)[0]- sometimes you might not be getting any elements , so when you try to access0-thelement it throws errorif len(ia.search_movie(item)):like so before that line