On Tue, 13 Apr 2010 02:46:39 am Dave Angel wrote:
> Or more readably:
>
> from string import lowercase as letters
> for c1 in letters:
>      for c2 in letters:
>          for c3 in letters:
>                 print c1+c2+c3


Here's another solution, for those using Python 2.6 or better:


>>> import itertools
>>> for x in itertools.product('abc', 'abc', 'abc'):
...     print ''.join(x)
...
aaa
aab
aac
aba
abb
abc
[many more lines...]
ccc


If you don't like the repeated 'abc' in the call to product(), it can be 
written as itertools.product(*['ab']*3) instead.





-- 
Steven D'Aprano
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to