Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

duplicates in python list

def findDuplicates(items):
    """ This function returns dict of duplicates items in Iterable
        and how much times it gets repeated in key value pair"""
    result = {}
    item = sorted(items)
    for i in item:
        if item.count(i) > 1:
            result.update({i: items.count(i)})
    return result
  
print(findDuplicates([1,2,3,4,3,4,2,7,4,7,8]))
# output will be {2: 2, 3: 2, 4: 3, 7: 2}
Source by www.pythonprogramming.in #
 
PREVIOUS NEXT
Tagged: #duplicates #python #list
ADD COMMENT
Topic
Name
7+6 =