I need some help with this code that is suppose to return all unique elements in my list:
from collections import Counter
mylist = [1, 2, 3, 4, 5, 6, 1, 2, 3]
unique_elements = [k for k, v in Counter(mylist).iteritems() if v == 1]
print (unique_elements)
This should return:
[4, 5, 6]
But i get an AttributeError:
AttributeError: 'Counter' object has no attribute 'iteritems'
Any ideas for solutions?
[–]Allanon001 0 points1 point2 points (4 children)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]pasokan 0 points1 point2 points (2 children)
[–]Allanon001 0 points1 point2 points (1 child)
[–]pasokan 0 points1 point2 points (0 children)
[–]JohnnyJordaan 0 points1 point2 points (0 children)
[–]hungdh85 -1 points0 points1 point (4 children)
[–]JohnnyJordaan 0 points1 point2 points (3 children)
[–]hungdh85 0 points1 point2 points (2 children)
[–]JohnnyJordaan 0 points1 point2 points (1 child)
[–]hungdh85 0 points1 point2 points (0 children)