Most elegant way to generate 3-char sequence
aisaac0 at verizon.net
Sat Jun 10 00:19:54 CEST 2006
"Rob Cowie" <cowie.rob at gmail.com> wrote in message
news:1149889784.391965.271570 at h76g2000cwa.googlegroups.com...
> 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.
More information about the Python-list