Most elegant way to generate 3-char sequence

David Isaac aisaac0 at
Sat Jun 10 00:19:54 CEST 2006

"Rob Cowie" <cowie.rob at> wrote in message
news:1149889784.391965.271570 at
> 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

Basically fine, but you only need one string.  E.g.,
alpha = "abcd"
used three times.

Alan Isaac

More information about the Python-list mailing list