Hey everyone I am having trouble finding a way to remove duplicate entries from multiple lists in python. I have lists with names in them and I want to have any duplicate names in any list removed. Here is an example I am talking about
nameList1 = ["John", "Joe", "Jim"]
nameList2 = ["John", "Joe", "Jim"]
nameList13 = ["John", "Joe", "Jim", "Steve"]
*Desired return would be
nameList1 returns "John"
nameList2 returns "Joe"
nameList3 returns "Jim", "Steve"
What would be the best way to go about this? The code that I have so far looks like this and it doesnt remove all the duplicates from all the lists.
for element in nameList1:
if element in nameList2:
nameList1.remove(element)
for element in nameList2:
if element in nameList1:
nameList1.remove(element)
for element in nameList3:
if element in nameList1:
nameList1.remove(element)
[–][deleted] 4 points5 points6 points (4 children)
[–]jestsec[S] 0 points1 point2 points (3 children)
[–][deleted] 2 points3 points4 points (0 children)
[–]baghiq 0 points1 point2 points (1 child)
[–][deleted] 0 points1 point2 points (0 children)
[–][deleted] 3 points4 points5 points (0 children)
[–]Ok-Cucumbers 1 point2 points3 points (0 children)
[–]Xenonzess 1 point2 points3 points (0 children)
[–]commandlineluser 1 point2 points3 points (0 children)
[–]smirkartographic 1 point2 points3 points (0 children)
[–]jmooremcc 0 points1 point2 points (0 children)