def prefixes(seq):
 n = len(seq)
 for i in range(n):
  (yield seq[:(i + 1)])

def prefixes ( seq ) : n = len ( seq ) for i in range ( n ) : ( yield seq [ : ( i + 1 ) ] )
generate all prefixes of a sequence .