Find duplicate elements in a list

There is a list, find the repeated elements in the list, such as list1 = [1,2,4,3,6,4]

 method one,

list1 = [1,2,4,3,6,4]
myset = set(list1)
for each in myset:
    print each,list1.count(each)

 

 

 Method 2, Counter()

list1 = [1,2,4,3,6,4]
from collections import Counter
c = Counter(list1)

  

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324779575&siteId=291194637