On 2006-06-09, Rob Cowie <[EMAIL PROTECTED]> wrote: > Hi all, > > I wish to generate a sequence of the form 'aaa', 'aab', aac'.... 'aba', > 'abb', 'abc' etc. all the way to 'zzz'. > > How would you construct a generator to acheive this? > > A simple, working but somewhat inelegant solution is... > > alpha = ['a','b','c','d'] #shortened for brevity > alpha2 = ['a','b','c','d'] > alpha3 = ['a','b','c','d'] > > def generator(): > for char in alpha: > for char2 in alpha2: > for char3 in alpha3: > yield char + char2 + char3
Why three separate lists? Why not alpha = ['a','b','c','d'] #shortened for brevity def generator(): for char in alpha: for char2 in alpha: for char3 in alpha: yield char + char2 + char3 -- Grant Edwards grante Yow! I think I am an at overnight sensation right visi.com now!! -- http://mail.python.org/mailman/listinfo/python-list