result = {}
for d in defectdetails:
    if d[0] not in result:
        result[d[0]] = {(1): 0, (2): 0, (3): 0}
result[d[0]][d[1]] += 1
for d, defects in sorted(result.items()):
    print('%s, 1: %d, 2: %d, 3: %d, total: %d' % (d, defects[1], defects[2],
        defects[3], sum(n for n in list(defects.values()))))
Python- Count number of occurrences of a date in a list