I am dealing with some kind of problem and i could not find any solution. My problem is I am controlling a value in a nested list if it is not in another list and deleting it if it is not there but in the not in line it gives me an error like index out of range.
def heroes_updater(men_pref,women):
for i in range(0,len(men_pref)-1):
for j in range(0,len(men_pref[i])-1):
if men_pref[i][j] not in women:
men_pref[i]=men_pref[i][:j]+men_pref[i][j+1:]
example men_pref:
[['Storm', 'Black Widow', 'Scarlet Witch', 'Rouge', 'Mystique', 'Jean Grey', 'Ms. Marvel', 'Gamora', 'Invisible Woman', 'Elektra'], ['Storm', 'Elektra', 'Jean Grey', 'Scarlet Witch', 'Mystique', 'Ms. Marvel', 'Gamora', 'Rouge', 'Black Widow', 'Invisible Woman'], ['Invisible Woman', 'Scarlet Witch', 'Mystique', 'Black Widow', 'Ms. Marvel', 'Elektra', 'Jean Grey', 'Gamora', 'Storm', 'Rouge']]
example women:
['Jean Grey', 'Elektra', 'Mystique', 'Ms. Marvel', 'Rouge']
And the error is :
if men_pref[i][j] not in women:
IndexError: list index out of range