1 回答
TA贡献1829条经验 获得超4个赞
更新:这将澄清你的两个问题。谢谢。
blocks = [ "0", "1a", "2a", "2b" ] # variables
num_blocks = len( blocks )
num_places = 4 # number of places
for i in range( pow( len( blocks ), num_places ) ):
value = i
indexes = []
while value:
indexes.append(value % num_blocks)
value = value // num_blocks
# print( i + 1 ) # alternatively print number of each permutation
output = ''
for j in range( len( indexes ), num_places ):
output += str(blocks[ num_blocks - 1 ])
for j in range( len( indexes ) - 1, -1, -1 ):
output += str(blocks[ num_blocks - 1 - indexes[j] ])
search = blocks[3] # search '2b' in output
if output.find(search) != -1 :
print output,
print " "
添加回答
举报