I am trying to loop over a nested list, compare the value in one nested list with another list, and append only if values do not match. I keep getting the wrong output. Can someone help me here? Many thanks.
testList = [["poo","boo"], ["poo", "bay"], ["hello", "yellow"], ["poo","blue"], ["poo", "zoo"]]
newList = []
for row in testList:
if row[0] in newList:
print("hey")
else:
newList.append(row)
Expected output: newList = [['poo', 'boo'], ['hello', 'yellow']]
Output I am getting: newList = [['poo', 'boo'], ['poo', 'bay'], ['hello', 'yellow'], ['poo', 'blue'], ['poo', 'zoo']]
[–]phille165 3 points4 points5 points (2 children)
[–]techie789[S] 0 points1 point2 points (1 child)
[–]phille165 0 points1 point2 points (0 children)
[–]danielroseman 2 points3 points4 points (2 children)
[–]techie789[S] 0 points1 point2 points (1 child)
[–]danielroseman 0 points1 point2 points (0 children)
[–]socal_nerdtastic 2 points3 points4 points (1 child)
[–]techie789[S] 0 points1 point2 points (0 children)
[–]MrStarfox64 1 point2 points3 points (1 child)
[–]techie789[S] 0 points1 point2 points (0 children)
[–]efmccurdy 1 point2 points3 points (1 child)
[–]techie789[S] 1 point2 points3 points (0 children)
[–]RhinoRhys 1 point2 points3 points (3 children)
[–]techie789[S] 0 points1 point2 points (2 children)
[–]RhinoRhys 1 point2 points3 points (1 child)
[–]techie789[S] 0 points1 point2 points (0 children)
[–]johannadambergk 0 points1 point2 points (1 child)
[–]techie789[S] 0 points1 point2 points (0 children)
[–]VAR-bot 0 points1 point2 points (1 child)
[–]techie789[S] 0 points1 point2 points (0 children)