def _count_diff_all_purpose(actual, expected):
 (s, t) = (list(actual), list(expected))
 (m, n) = (len(s), len(t))
 NULL = object()
 result = []
 for (i, elem) in enumerate(s):
  if (elem is NULL):
   continue
  cnt_s = cnt_t = 0
  for j in range(i, m):
   if (s[j] == elem):
    cnt_s += 1
    s[j] = NULL
  for (j, other_elem) in enumerate(t):
   if (other_elem == elem):
    cnt_t += 1
    t[j] = NULL
  if (cnt_s != cnt_t):
   diff = _Mismatch(cnt_s, cnt_t, elem)
   result.append(diff)
 for (i, elem) in enumerate(t):
  if (elem is NULL):
   continue
  cnt_t = 0
  for j in range(i, n):
   if (t[j] == elem):
    cnt_t += 1
    t[j] = NULL
  diff = _Mismatch(0, cnt_t, elem)
  result.append(diff)
 return result

def _count_diff_all_purpose ( actual , expected ) : ( s , t ) = ( list ( actual ) , list ( expected ) ) ( m , n ) = ( len ( s ) , len ( t ) ) NULL = object ( ) result = [ ] for ( i , elem ) in enumerate ( s ) : if ( elem is NULL ) : continue cnt_s = cnt_t = 0 for j in range ( i , m ) : if ( s [ j ] == elem ) : cnt_s += 1 s [ j ] = NULL for ( j , other_elem ) in enumerate ( t ) : if ( other_elem == elem ) : cnt_t += 1 t [ j ] = NULL if ( cnt_s != cnt_t ) : diff = _Mismatch ( cnt_s , cnt_t , elem ) result . append ( diff ) for ( i , elem ) in enumerate ( t ) : if ( elem is NULL ) : continue cnt_t = 0 for j in range ( i , n ) : if ( t [ j ] == elem ) : cnt_t += 1 t [ j ] = NULL diff = _Mismatch ( 0 , cnt_t , elem ) result . append ( diff ) return result
returns list of triples where the counts differ .