In an older post (Python: count repeated elements in the list), I noticed two replies (answer 3 and 5) that use set
to count repeated elements of a list.
In a question I asked myself recently (Compare lines in 2 text files with different number of columns), it was mentioned that a set
only contains unique elements; the python documentation says the same (https://docs.python.org/2/library/sets.html).
How does something like this work, if set
is supposed to contain unique elements only:
yourList = ["a", "b", "a", "c", "c", "a", "c"]
duplicateFrequencies = {}
for i in set(yourList):
duplicateFrequencies[i] = yourList.count(i)