def de_bruijn(alphabet=string.ascii_lowercase, n=None):
 if (n is None):
  n = 4
 k = len(alphabet)
 a = (([0] * k) * n)
 def db(t, p):
  if (t > n):
   if ((n % p) == 0):
    for j in range(1, (p + 1)):
     (yield alphabet[a[j]])
  else:
   a[t] = a[(t - p)]
   for c in db((t + 1), p):
    (yield c)
   for j in range((a[(t - p)] + 1), k):
    a[t] = j
    for c in db((t + 1), t):
     (yield c)
 return db(1, 1)

def de_bruijn ( alphabet = string . ascii_lowercase , n = None ) : if ( n is None ) : n = 4 k = len ( alphabet ) a = ( ( [ 0 ] * k ) * n ) def db ( t , p ) : if ( t > n ) : if ( ( n % p ) == 0 ) : for j in range ( 1 , ( p + 1 ) ) : ( yield alphabet [ a [ j ] ] ) else : a [ t ] = a [ ( t - p ) ] for c in db ( ( t + 1 ) , p ) : ( yield c ) for j in range ( ( a [ ( t - p ) ] + 1 ) , k ) : a [ t ] = j for c in db ( ( t + 1 ) , t ) : ( yield c ) return db ( 1 , 1 )
generate the de bruijn sequence up to maxlen characters for the charset charset and subsequences of length n .