def duplicates_indices(fields):
 (dup, ind) = (get_duplicates(fields), defaultdict(list))
 for (i, v) in enumerate(fields):
  if (v in dup):
   ind[v].append(i)
 return ind

def duplicates_indices ( fields ) : ( dup , ind ) = ( get_duplicates ( fields ) , defaultdict ( list ) ) for ( i , v ) in enumerate ( fields ) : if ( v in dup ) : ind [ v ] . append ( i ) return ind
gets dictionary of duplicates:locations in a list modified from stackoverflow .