制作字母表中每个可能的字母组合的最有效方法是什么?
E.g。 a,b,c,d,e ... z,aa,ab,ac,ad,ae ... ect
我编写了一个成功生成此结果的代码,但我觉得它在产生所需结果方面效率太低。
有什么想法吗?
我也试图解释我做了什么
#import module time
import time
#set starting variable "gen", make gen list.
gen =''
gen = list(gen)
#expermintal alphabet, not actually used
alpha ='abcdefghijklmnopqrstuvwxyz'
alpha = list(alpha)
#Approx. on time taken to complete x letters
useless_value = raw_input("Press Enter to continue...")
print "How many letters would you like to start at?"
useless_value = input("> ")
gen = gen*useless_value
#start time for function
start_time= time.time()
try:
gen[-1]
except IndexError:
print "INVALID LETTER RANGE"
print "DEFAULT LETTERS USED (1)"
gen = 'a'
gen = list(gen)
#function loop (will never break)
x=1
while True:
#print raw string of gen
print "".join(gen)
#since infinite loop within same function, variables have to be reset
#thus oh = 0 is reseting for later use
oh = 0
#change a to b, b to c... ect. Will only make one change
if gen[-1] =='a':
gen[-1] ='b'
elif gen[-1] =='b':
gen[-1] ='c'
elif gen[-1] =='c':
gen[-1] ='d'
elif gen[-1] =='d':
gen[-1] ='e'
elif gen[-1] =='e':
gen[-1] ='f'
elif gen[-1] =='f':
gen[-1] ='g'
elif gen[-1] =='g':
gen[-1] ='h'
elif gen[-1] =='h':
gen[-1] ='i'
elif gen[-1] =='i':
gen[-1] ='j'
elif gen[-1] =='j':
gen[-1] ='k'
elif gen[-1] =='k':
gen[-1] ='l'
elif gen[-1] =='l':
gen[-1] ='m'
elif gen[-1] =='m':
gen[-1] ='n'
elif gen[-1] =='n':
gen[-1] ='o'
elif gen[-1] =='o':
gen[-1] ='p'
elif gen[-1] =='p':
gen[-1] ='q'
elif gen[-1] =='q':
gen[-1] ='r'
elif gen[-1] =='r':
gen[-1] ='s'
elif gen[-1] =='s':
gen[-1] ='t'
elif gen[-1] =='t':
gen[-1] ='u'
elif gen[-1] =='u':
gen[-1] ='v'
elif gen[-1] =='v':
gen[-1] ='w'
elif gen[-1] =='w':
gen[-1] ='x'
elif gen[-1] =='x':
gen[-1] ='y'
#if 'y' changes to 'z'. variable 'oh' is set to '1'.
# This is so it doesn't enter unwanted equations
elif gen[-1] =='y':
gen[-1] ='z'
oh = 1
#if last string = 'z'
#Checks max length of gen through [-1,-2].. ect
if gen[-1] =='z':
#reset s
s = 0
x=1
while True:
try:
s
except NameError:
s = -1
s = s-1
try:
gen[s]
except IndexError:
s = s+1
break
#s = the amount that gen cannot be
#Therefore s+1 == max
#resets values because of loop
d= 0
q= 0
#this infinite loop checks the string to see if all string values = 'z'
#if it does it will change all values to 'a' then add 'a'
x=1
while True:
#useless piece of code #1
try:
d
except NameError:
d = 0
#useful
d = d-1
try:
gen[d]
except IndexError:
break
#if d value == 'z' it will continue, otherwise break from loop
if gen[d] =='z':
#if the max == the d value that means all values have been checked
#and = 'z'. Otherwise it would've already broken the loop
if s == d:
x=1
while True:
#if oh == 1 which was set from y changing to z
# it will not continue
#this is so that if 'zy' changes to 'zz' in the first
#loop it will not change to 'aaa' while still in the loop
# this is so it prints 'zz' and doesn't skip this
#This is important to assure all possible combinations are printed
if oh == 1:
break
else:
pass
#useless q already set to 0
try:
q
except NameError:
q = 0
#sets individually all values of 'z' to 'a'
q= q-1
try:
gen[q] ='a'
#then when q cannot exist, adds an 'a'
except IndexError:
gen = gen + ['a']
#sets oh = 1, just in case. most likely useless again
oh = 1
#prints time taken to complete amount of letters
print "Completed", ((len(gen))-1), "letters in", ((time.time() - start_time) /60), "minutes."
break
else:
continue
else:
break
#if the last value = 'z' it will find the next non 'z' value and make all
#values after it = 'a'. e.g. you have abczezzz
# it will check find the 'e' and change that 'e' to a 'f'
# then it will change all the z's after it to a's
# so final would be - abczfaaa
m = -1
if gen[-1] =='z':
x=1
while True:
if oh == 1:
break
else:
pass
m = m -1
if gen[m] =='a':
gen[m] ='b'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='b':
gen[m] ='c'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='c':
gen[m] ='d'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='d':
gen[m] ='e'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='e':
gen[m] ='f'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='f':
gen[m] ='g'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='g':
gen[m] ='h'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='h':
gen[m] ='i'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='i':
gen[m] ='j'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='j':
gen[m] ='k'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='k':
gen[m] ='l'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='l':
gen[m] ='m'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='m':
gen[m] ='n'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='n':
gen[m] ='o'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='o':
gen[m] ='p'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='p':
gen[m] ='q'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='q':
gen[m] ='r'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='r':
gen[m] ='s'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='s':
gen[m] ='t'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='t':
gen[m] ='u'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='u':
gen[m] ='v'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='v':
gen[m] ='w'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='w':
gen[m] ='x'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='x':
gen[m] ='y'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='y':
gen[m] ='z'
gen[(m+1):] = ('a')*(-(m+1))
break
elif gen[m] =='z':
continue
答案 0 :(得分:9)
使用itertools.product()
创建字母组合:
from string import ascii_lowercase
from itertools import product
for length in range(minimum_length, maximum_length + 1):
for combo in product(ascii_lowercase, repeat=length):
print ''.join(combo)
考虑到产生的组合数量随length
参数呈指数增长。
演示:
>>> minimum_length, maximum_length = 1, 2
>>> for length in range(minimum_length, maximum_length + 1):
... for combo in product(ascii_lowercase, repeat=length):
... print ''.join(combo)
...
a
b
c
d
e
f
g
h
i
j
k
l
m
n
o
p
q
r
s
t
u
v
w
x
y
z
aa
ab
ac
ad
ae
af
ag
ah
ai
aj
ak
al
am
an
ao
ap
aq
ar
as
at
au
av
aw
ax
ay
az
ba
bb
bc
bd
be
bf
bg
bh
bi
bj
bk
bl
bm
bn
bo
bp
bq
br
bs
bt
bu
bv
bw
bx
by
bz
ca
cb
cc
cd
ce
cf
cg
ch
ci
cj
ck
cl
cm
cn
co
cp
cq
cr
cs
ct
cu
cv
cw
cx
cy
cz
da
db
dc
dd
de
df
dg
dh
di
dj
dk
dl
dm
dn
do
dp
dq
dr
ds
dt
du
dv
dw
dx
dy
dz
ea
eb
ec
ed
ee
ef
eg
eh
ei
ej
ek
el
em
en
eo
ep
eq
er
es
et
eu
ev
ew
ex
ey
ez
fa
fb
fc
fd
fe
ff
fg
fh
fi
fj
fk
fl
fm
fn
fo
fp
fq
fr
fs
ft
fu
fv
fw
fx
fy
fz
ga
gb
gc
gd
ge
gf
gg
gh
gi
gj
gk
gl
gm
gn
go
gp
gq
gr
gs
gt
gu
gv
gw
gx
gy
gz
ha
hb
hc
hd
he
hf
hg
hh
hi
hj
hk
hl
hm
hn
ho
hp
hq
hr
hs
ht
hu
hv
hw
hx
hy
hz
ia
ib
ic
id
ie
if
ig
ih
ii
ij
ik
il
im
in
io
ip
iq
ir
is
it
iu
iv
iw
ix
iy
iz
ja
jb
jc
jd
je
jf
jg
jh
ji
jj
jk
jl
jm
jn
jo
jp
jq
jr
js
jt
ju
jv
jw
jx
jy
jz
ka
kb
kc
kd
ke
kf
kg
kh
ki
kj
kk
kl
km
kn
ko
kp
kq
kr
ks
kt
ku
kv
kw
kx
ky
kz
la
lb
lc
ld
le
lf
lg
lh
li
lj
lk
ll
lm
ln
lo
lp
lq
lr
ls
lt
lu
lv
lw
lx
ly
lz
ma
mb
mc
md
me
mf
mg
mh
mi
mj
mk
ml
mm
mn
mo
mp
mq
mr
ms
mt
mu
mv
mw
mx
my
mz
na
nb
nc
nd
ne
nf
ng
nh
ni
nj
nk
nl
nm
nn
no
np
nq
nr
ns
nt
nu
nv
nw
nx
ny
nz
oa
ob
oc
od
oe
of
og
oh
oi
oj
ok
ol
om
on
oo
op
oq
or
os
ot
ou
ov
ow
ox
oy
oz
pa
pb
pc
pd
pe
pf
pg
ph
pi
pj
pk
pl
pm
pn
po
pp
pq
pr
ps
pt
pu
pv
pw
px
py
pz
qa
qb
qc
qd
qe
qf
qg
qh
qi
qj
qk
ql
qm
qn
qo
qp
qq
qr
qs
qt
qu
qv
qw
qx
qy
qz
ra
rb
rc
rd
re
rf
rg
rh
ri
rj
rk
rl
rm
rn
ro
rp
rq
rr
rs
rt
ru
rv
rw
rx
ry
rz
sa
sb
sc
sd
se
sf
sg
sh
si
sj
sk
sl
sm
sn
so
sp
sq
sr
ss
st
su
sv
sw
sx
sy
sz
ta
tb
tc
td
te
tf
tg
th
ti
tj
tk
tl
tm
tn
to
tp
tq
tr
ts
tt
tu
tv
tw
tx
ty
tz
ua
ub
uc
ud
ue
uf
ug
uh
ui
uj
uk
ul
um
un
uo
up
uq
ur
us
ut
uu
uv
uw
ux
uy
uz
va
vb
vc
vd
ve
vf
vg
vh
vi
vj
vk
vl
vm
vn
vo
vp
vq
vr
vs
vt
vu
vv
vw
vx
vy
vz
wa
wb
wc
wd
we
wf
wg
wh
wi
wj
wk
wl
wm
wn
wo
wp
wq
wr
ws
wt
wu
wv
ww
wx
wy
wz
xa
xb
xc
xd
xe
xf
xg
xh
xi
xj
xk
xl
xm
xn
xo
xp
xq
xr
xs
xt
xu
xv
xw
xx
xy
xz
ya
yb
yc
yd
ye
yf
yg
yh
yi
yj
yk
yl
ym
yn
yo
yp
yq
yr
ys
yt
yu
yv
yw
yx
yy
yz
za
zb
zc
zd
ze
zf
zg
zh
zi
zj
zk
zl
zm
zn
zo
zp
zq
zr
zs
zt
zu
zv
zw
zx
zy
zz
答案 1 :(得分:0)
如果您只想要没有任何花哨范围计算的字母组合,列表推导是构建字母组合的一种非常简单的方法。
letters = 'abcdefghijklmnopqrstuvwxyz'
[(a, b) for a in letters for b in letters]
在口译员中尝试。你会得到:
[('a', 'a'), ('a', 'b'), ('a', 'c'), ('a', 'd'), ('a', 'e'), ('a', 'f'), ('a', 'g'), ('a', 'h'), ('a', 'i'), ('a', 'j'), ('a', 'k'), ('a', 'l'), ('a', 'm'), ('a', 'n'), ('a', 'o'), ('a', 'p'), ('a', 'q'), ('a', 'r'), ('a', 's'), ('a', 't'), ('a', 'u'), ('a', 'v'), ('a', 'w'), ('a', 'x'), ('a', 'y'), ('a', 'z'), ('b', 'a'), ('b', 'b'), ('b', 'c'), ('b', 'd'), ('b', 'e'), ('b', 'f'), ('b', 'g'), ('b', 'h'), ('b', 'i'), ('b', 'j'), ('b', 'k'), ('b', 'l'), ('b', 'm'), ('b', 'n'), ('b', 'o'), ('b', 'p'), ('b', 'q'), ('b', 'r'), ('b', 's'), ('b', 't'), ('b', 'u'), ('b', 'v'), ('b', 'w'), ('b', 'x'), ('b', 'y'), ('b', 'z'), ('c', 'a'), ('c', 'b'), ('c', 'c'), ('c', 'd'), ('c', 'e'), ('c', 'f'), ('c', 'g'), ('c', 'h'), ('c', 'i'), ('c', 'j'), ('c', 'k'), ('c', 'l'), ('c', 'm'), ('c', 'n'), ('c', 'o'), ('c', 'p'), ('c', 'q'), ('c', 'r'), ('c', 's'), ('c', 't'), ('c', 'u'), ('c', 'v'), ('c', 'w'), ('c', 'x'), ('c', 'y'), ('c', 'z'), ('d', 'a'), ('d', 'b'), ('d', 'c'), ('d', 'd'), ('d', 'e'), ('d', 'f'), ('d', 'g'), ('d', 'h'), ('d', 'i'), ('d', 'j'), ('d', 'k'), ('d', 'l'), ('d', 'm'), ('d', 'n'), ('d', 'o'), ('d', 'p'), ('d', 'q'), ('d', 'r'), ('d', 's'), ('d', 't'), ('d', 'u'), ('d', 'v'), ('d', 'w'), ('d', 'x'), ('d', 'y'), ('d', 'z'), ('e', 'a'), ('e', 'b'), ('e', 'c'), ('e', 'd'), ('e', 'e'), ('e', 'f'), ('e', 'g'), ('e', 'h'), ('e', 'i'), ('e', 'j'), ('e', 'k'), ('e', 'l'), ('e', 'm'), ('e', 'n'), ('e', 'o'), ('e', 'p'), ('e', 'q'), ('e', 'r'), ('e', 's'), ('e', 't'), ('e', 'u'), ('e', 'v'), ('e', 'w'), ('e', 'x'), ('e', 'y'), ('e', 'z'), ('f', 'a'), ('f', 'b'), ('f', 'c'), ('f', 'd'), ('f', 'e'), ('f', 'f'), ('f', 'g'), ('f', 'h'), ('f', 'i'), ('f', 'j'), ('f', 'k'), ('f', 'l'), ('f', 'm'), ('f', 'n'), ('f', 'o'), ('f', 'p'), ('f', 'q'), ('f', 'r'), ('f', 's'), ('f', 't'), ('f', 'u'), ('f', 'v'), ('f', 'w'), ('f', 'x'), ('f', 'y'), ('f', 'z'), ('g', 'a'), ('g', 'b'), ('g', 'c'), ('g', 'd'), ('g', 'e'), ('g', 'f'), ('g', 'g'), ('g', 'h'), ('g', 'i'), ('g', 'j'), ('g', 'k'), ('g', 'l'), ('g', 'm'), ('g', 'n'), ('g', 'o'), ('g', 'p'), ('g', 'q'), ('g', 'r'), ('g', 's'), ('g', 't'), ('g', 'u'), ('g', 'v'), ('g', 'w'), ('g', 'x'), ('g', 'y'), ('g', 'z'), ('h', 'a'), ('h', 'b'), ('h', 'c'), ('h', 'd'), ('h', 'e'), ('h', 'f'), ('h', 'g'), ('h', 'h'), ('h', 'i'), ('h', 'j'), ('h', 'k'), ('h', 'l'), ('h', 'm'), ('h', 'n'), ('h', 'o'), ('h', 'p'), ('h', 'q'), ('h', 'r'), ('h', 's'), ('h', 't'), ('h', 'u'), ('h', 'v'), ('h', 'w'), ('h', 'x'), ('h', 'y'), ('h', 'z'), ('i', 'a'), ('i', 'b'), ('i', 'c'), ('i', 'd'), ('i', 'e'), ('i', 'f'), ('i', 'g'), ('i', 'h'), ('i', 'i'), ('i', 'j'), ('i', 'k'), ('i', 'l'), ('i', 'm'), ('i', 'n'), ('i', 'o'), ('i', 'p'), ('i', 'q'), ('i', 'r'), ('i', 's'), ('i', 't'), ('i', 'u'), ('i', 'v'), ('i', 'w'), ('i', 'x'), ('i', 'y'), ('i', 'z'), ('j', 'a'), ('j', 'b'), ('j', 'c'), ('j', 'd'), ('j', 'e'), ('j', 'f'), ('j', 'g'), ('j', 'h'), ('j', 'i'), ('j', 'j'), ('j', 'k'), ('j', 'l'), ('j', 'm'), ('j', 'n'), ('j', 'o'), ('j', 'p'), ('j', 'q'), ('j', 'r'), ('j', 's'), ('j', 't'), ('j', 'u'), ('j', 'v'), ('j', 'w'), ('j', 'x'), ('j', 'y'), ('j', 'z'), ('k', 'a'), ('k', 'b'), ('k', 'c'), ('k', 'd'), ('k', 'e'), ('k', 'f'), ('k', 'g'), ('k', 'h'), ('k', 'i'), ('k', 'j'), ('k', 'k'), ('k', 'l'), ('k', 'm'), ('k', 'n'), ('k', 'o'), ('k', 'p'), ('k', 'q'), ('k', 'r'), ('k', 's'), ('k', 't'), ('k', 'u'), ('k', 'v'), ('k', 'w'), ('k', 'x'), ('k', 'y'), ('k', 'z'), ('l', 'a'), ('l', 'b'), ('l', 'c'), ('l', 'd'), ('l', 'e'), ('l', 'f'), ('l', 'g'), ('l', 'h'), ('l', 'i'), ('l', 'j'), ('l', 'k'), ('l', 'l'), ('l', 'm'), ('l', 'n'), ('l', 'o'), ('l', 'p'), ('l', 'q'), ('l', 'r'), ('l', 's'), ('l', 't'), ('l', 'u'), ('l', 'v'), ('l', 'w'), ('l', 'x'), ('l', 'y'), ('l', 'z'), ('m', 'a'), ('m', 'b'), ('m', 'c'), ('m', 'd'), ('m', 'e'), ('m', 'f'), ('m', 'g'), ('m', 'h'), ('m', 'i'), ('m', 'j'), ('m', 'k'), ('m', 'l'), ('m', 'm'), ('m', 'n'), ('m', 'o'), ('m', 'p'), ('m', 'q'), ('m', 'r'), ('m', 's'), ('m', 't'), ('m', 'u'), ('m', 'v'), ('m', 'w'), ('m', 'x'), ('m', 'y'), ('m', 'z'), ('n', 'a'), ('n', 'b'), ('n', 'c'), ('n', 'd'), ('n', 'e'), ('n', 'f'), ('n', 'g'), ('n', 'h'), ('n', 'i'), ('n', 'j'), ('n', 'k'), ('n', 'l'), ('n', 'm'), ('n', 'n'), ('n', 'o'), ('n', 'p'), ('n', 'q'), ('n', 'r'), ('n', 's'), ('n', 't'), ('n', 'u'), ('n', 'v'), ('n', 'w'), ('n', 'x'), ('n', 'y'), ('n', 'z'), ('o', 'a'), ('o', 'b'), ('o', 'c'), ('o', 'd'), ('o', 'e'), ('o', 'f'), ('o', 'g'), ('o', 'h'), ('o', 'i'), ('o', 'j'), ('o', 'k'), ('o', 'l'), ('o', 'm'), ('o', 'n'), ('o', 'o'), ('o', 'p'), ('o', 'q'), ('o', 'r'), ('o', 's'), ('o', 't'), ('o', 'u'), ('o', 'v'), ('o', 'w'), ('o', 'x'), ('o', 'y'), ('o', 'z'), ('p', 'a'), ('p', 'b'), ('p', 'c'), ('p', 'd'), ('p', 'e'), ('p', 'f'), ('p', 'g'), ('p', 'h'), ('p', 'i'), ('p', 'j'), ('p', 'k'), ('p', 'l'), ('p', 'm'), ('p', 'n'), ('p', 'o'), ('p', 'p'), ('p', 'q'), ('p', 'r'), ('p', 's'), ('p', 't'), ('p', 'u'), ('p', 'v'), ('p', 'w'), ('p', 'x'), ('p', 'y'), ('p', 'z'), ('q', 'a'), ('q', 'b'), ('q', 'c'), ('q', 'd'), ('q', 'e'), ('q', 'f'), ('q', 'g'), ('q', 'h'), ('q', 'i'), ('q', 'j'), ('q', 'k'), ('q', 'l'), ('q', 'm'), ('q', 'n'), ('q', 'o'), ('q', 'p'), ('q', 'q'), ('q', 'r'), ('q', 's'), ('q', 't'), ('q', 'u'), ('q', 'v'), ('q', 'w'), ('q', 'x'), ('q', 'y'), ('q', 'z'), ('r', 'a'), ('r', 'b'), ('r', 'c'), ('r', 'd'), ('r', 'e'), ('r', 'f'), ('r', 'g'), ('r', 'h'), ('r', 'i'), ('r', 'j'), ('r', 'k'), ('r', 'l'), ('r', 'm'), ('r', 'n'), ('r', 'o'), ('r', 'p'), ('r', 'q'), ('r', 'r'), ('r', 's'), ('r', 't'), ('r', 'u'), ('r', 'v'), ('r', 'w'), ('r', 'x'), ('r', 'y'), ('r', 'z'), ('s', 'a'), ('s', 'b'), ('s', 'c'), ('s', 'd'), ('s', 'e'), ('s', 'f'), ('s', 'g'), ('s', 'h'), ('s', 'i'), ('s', 'j'), ('s', 'k'), ('s', 'l'), ('s', 'm'), ('s', 'n'), ('s', 'o'), ('s', 'p'), ('s', 'q'), ('s', 'r'), ('s', 's'), ('s', 't'), ('s', 'u'), ('s', 'v'), ('s', 'w'), ('s', 'x'), ('s', 'y'), ('s', 'z'), ('t', 'a'), ('t', 'b'), ('t', 'c'), ('t', 'd'), ('t', 'e'), ('t', 'f'), ('t', 'g'), ('t', 'h'), ('t', 'i'), ('t', 'j'), ('t', 'k'), ('t', 'l'), ('t', 'm'), ('t', 'n'), ('t', 'o'), ('t', 'p'), ('t', 'q'), ('t', 'r'), ('t', 's'), ('t', 't'), ('t', 'u'), ('t', 'v'), ('t', 'w'), ('t', 'x'), ('t', 'y'), ('t', 'z'), ('u', 'a'), ('u', 'b'), ('u', 'c'), ('u', 'd'), ('u', 'e'), ('u', 'f'), ('u', 'g'), ('u', 'h'), ('u', 'i'), ('u', 'j'), ('u', 'k'), ('u', 'l'), ('u', 'm'), ('u', 'n'), ('u', 'o'), ('u', 'p'), ('u', 'q'), ('u', 'r'), ('u', 's'), ('u', 't'), ('u', 'u'), ('u', 'v'), ('u', 'w'), ('u', 'x'), ('u', 'y'), ('u', 'z'), ('v', 'a'), ('v', 'b'), ('v', 'c'), ('v', 'd'), ('v', 'e'), ('v', 'f'), ('v', 'g'), ('v', 'h'), ('v', 'i'), ('v', 'j'), ('v', 'k'), ('v', 'l'), ('v', 'm'), ('v', 'n'), ('v', 'o'), ('v', 'p'), ('v', 'q'), ('v', 'r'), ('v', 's'), ('v', 't'), ('v', 'u'), ('v', 'v'), ('v', 'w'), ('v', 'x'), ('v', 'y'), ('v', 'z'), ('w', 'a'), ('w', 'b'), ('w', 'c'), ('w', 'd'), ('w', 'e'), ('w', 'f'), ('w', 'g'), ('w', 'h'), ('w', 'i'), ('w', 'j'), ('w', 'k'), ('w', 'l'), ('w', 'm'), ('w', 'n'), ('w', 'o'), ('w', 'p'), ('w', 'q'), ('w', 'r'), ('w', 's'), ('w', 't'), ('w', 'u'), ('w', 'v'), ('w', 'w'), ('w', 'x'), ('w', 'y'), ('w', 'z'), ('x', 'a'), ('x', 'b'), ('x', 'c'), ('x', 'd'), ('x', 'e'), ('x', 'f'), ('x', 'g'), ('x', 'h'), ('x', 'i'), ('x', 'j'), ('x', 'k'), ('x', 'l'), ('x', 'm'), ('x', 'n'), ('x', 'o'), ('x', 'p'), ('x', 'q'), ('x', 'r'), ('x', 's'), ('x', 't'), ('x', 'u'), ('x', 'v'), ('x', 'w'), ('x', 'x'), ('x', 'y'), ('x', 'z'), ('y', 'a'), ('y', 'b'), ('y', 'c'), ('y', 'd'), ('y', 'e'), ('y', 'f'), ('y', 'g'), ('y', 'h'), ('y', 'i'), ('y', 'j'), ('y', 'k'), ('y', 'l'), ('y', 'm'), ('y', 'n'), ('y', 'o'), ('y', 'p'), ('y', 'q'), ('y', 'r'), ('y', 's'), ('y', 't'), ('y', 'u'), ('y', 'v'), ('y', 'w'), ('y', 'x'), ('y', 'y'), ('y', 'z'), ('z', 'a'), ('z', 'b'), ('z', 'c'), ('z', 'd'), ('z', 'e'), ('z', 'f'), ('z', 'g'), ('z', 'h'), ('z', 'i'), ('z', 'j'), ('z', 'k'), ('z', 'l'), ('z', 'm'), ('z', 'n'), ('z', 'o'), ('z', 'p'), ('z', 'q'), ('z', 'r'), ('z', 's'), ('z', 't'), ('z', 'u'), ('z', 'v'), ('z', 'w'), ('z', 'x'), ('z', 'y'), ('z', 'z')]
您可以根据需要调整字母范围,以获得您想要的内容。比itertools.product
更容易理解。