Skip to content Skip to sidebar Skip to footer

Valueerror: 0 Is Not In List When Running This Code

I'm currently working on a little side project yet having multiple issues. I'm reading a file within the folder where the project is that holds data for 10 users. As for the code i

Solution 1:

accessing element of list is done by list_name[index],list_name.index(element) returns the index of that element,if they are two in the list it returns the index of the first one, if the element is not there,it throws a ValueError: "element" is not in the list. in your case change

usager_matrice = matrice_similarite.index(id_usager)

to

usager_matrice =matrice_similarite[id_usager]

and other places you want to access element of a list using index

in the scond question from the comment, check if its numeric like this

id_usager =input("Entrer l'ID de l'usager pour lequel vous voulez une recommandation (entre 0 et {}):".format(n))

ifnot id_usager.isdigit():
   continue
id_user=int(id_usager)

note that this will convert also floats into int

Post a Comment for "Valueerror: 0 Is Not In List When Running This Code"