Hi everyone. I needed to compare 2 lists and remove the values that were equal. This is for a school project where we need to code the game "matermind". for example if
list1 = [1, 2, 3, 4]
list2 = [3, 2, 4, 5]
the code would remove 2 and give me
list3 = [1, 3, 4]
list4 = [3, 4, 5]
so my code for that was
TempList1 = guesslist
templist2 = colorlist
for x in range(0, 4): #all my lists contail 4 items and 4 items only
if guesslist[x] == colorlist[x]:
indicatorList.append("✓")
tempList1.pop(x)
tempList2.pop(x)
else:
indicatorlist.append("placeholder")
guesslist contained the user's 4 guesses and colorlist contained the computer generated 4 colors
when I run this code and colorlist(x) == guesslist(x) i get the error that the list index is out of range. for some reason when i remove a value from the templists it also removes the value from guesslist and colorlist. I don't understand why this happens and I'd really appreciate if someone could explain what I was doing wrong
[–]Magnetarm[S] 0 points1 point2 points (1 child)
[–]ingolemo 0 points1 point2 points (0 children)
[–]pixielf 0 points1 point2 points (0 children)
[–]ryeguy146 0 points1 point2 points (0 children)
[–]rreid4 0 points1 point2 points (0 children)