ValueError: list.remove(x): x not in list (python 3.2)

问题内容:

I keep getting this error when running my code:

ValueError: list.remove(x): x not in list

With this code I’m supposed to check the elements in lst and in listOfOperatorsDomains. If they are the same (I used [if x in y] and not [if x == y] because of the context), then I append those two values to another list (listOfRequestsAssigned) and remove the element y from lst. However, the line where I remove the element y is giving me that error.
My code:

for y in lst: 
    for k in listOfOperatorsDomains:
        if y[2] in k:
            element = listOfOperatorsDomains.index(k)
            listOfRequestsAssigned.append([y[0],operators[element][0],"assigned"])
            lst.remove(y)
return listOfRequestsAssigned

问题评论:

    
please have a read here for MCVE. we need at least a minimal sample list to work with (which we could simply copy paste and get right to your problem), that’s for not wasting everyone’s time, including yours as well. thanks a lot!

原文地址:

https://stackoverflow.com/questions/47756425/valueerror-list-removex-x-not-in-list-python-3-2

Tags:,

Add a Comment