python - identify repeating elements in list

Reprinted: https://blog.csdn.net/August1226/article/details/82144759

 

【problem solved】

from collections import Counter # incorporated Counter
A = [29,36,57,12,79,43,23,56,28,11,14,15,16,37,24,35,17,24,33,15, 39,46,52,13]
B = dict (Counter (A))
Print ([Key for Key, b.items value in () IF value>. 1]) show only repeating elements #
print ({key: value for key , value in b.items () if value > 1}) # show the duplicate elements and the number of repetitions
test results show:

 

 

 

carry out! 

 

Guess you like

Origin www.cnblogs.com/wsnan/p/11670851.html