|
本帖最后由 cdbclx 于 2017-7-18 07:01 编辑
如果确定最多只有两种变化,就可以简单些,考虑到可能有更多变化,所以写的复杂了点:
import copy
L=[]
str='12345'
dd={'1':('1','E'),'2':('2','R'),'5':('5','U')}
a=[]
for i in str:
if i in dd:
a.append(dd)
else:
a.append((i,))
for i in a:
l=len(i)
ll=len(L)
if l>1:
if ll==0:
for ii in i:
L.append([ii])
else:
for xx in range(l-1):
for LL in range(ll):
L.append(copy.deepcopy(L[LL]))
for ii in range(l):
for LL in range(ll):
L[ii*ll+LL].append(i[ii])
else:
if ll==0:
L.append(i[0])
else:
for xxx in range(ll):
L[xxx].append(i[0])
for i in L:
print ''.join(i)
运行结果:
12345
E2345
1R345
ER345
1234U
E234U
1R34U
ER34U
>>>
|
|