Python:遍历列表中所有整数并得出所有可能值的算法?

Python:遍历列表中所有整数并得出所有可能值的算法?,python,algorithm,Python,Algorithm,查看列表中的最后一个占位符,将其递增一 list = [0,0,...0] 将其递增到1到100之间的随机整数值范围 一旦最后一个位置值位于范围的末尾,将此占位符重置为零,移动到上一个占位符并递增,然后查看下一个占位符并重复上面的操作 [0,0,...1] [0,0,...2] [0,0,...3] .. .. [0,0,...82] #stop at the last integer in range from 1 to 89 (randomly generated) 这将一直持续,直到列

查看列表中的最后一个占位符,将其递增一

list = [0,0,...0]
将其递增到1到100之间的随机整数值范围 一旦最后一个位置值位于范围的末尾,将此占位符重置为零,移动到上一个占位符并递增,然后查看下一个占位符并重复上面的操作

[0,0,...1]
[0,0,...2]
[0,0,...3]
..
..
[0,0,...82] #stop at the last integer in range from 1 to 89 (randomly generated)

这将一直持续,直到列表中的所有整数都已递增。

listLen
设置为列表中要开始的
int
s的数目

[0,0,..1,0]
[0,0,..1,1]
[0,0,..1,2]
[0,0,..1,3]
..
..
[0,0,..1,77]
##################

[0,0,..2,0]
[0,0,..2,1]
[0,0,..2,2]
[0,0,..2,3]
..
..
[0,0,..2,41]
##################

[0,0,..1,0,0]
[0,0,..1,0,1]
[0,0,..1,0,2]
[0,0,..1,1,0]
[0,0,..1,1,1]
[0,0,..1,1,2]
[0,0,..1,1,3]
[0,0,..1,1,0]
[0,0,..1,2,0]
[0,0,..1,2,1]
[0,0,..1,2,2]
[0,0,..2,0,0]
[0,0,..2,0,1]
[0,0,..2,1,0]
[0,0,..2,1,1]
[0,0,..2,1,2]
[0,0,..2,1,3]
[0,0,..2,1,4]
##################
如果要为每个列表选择不同的随机数,则可以改为:

listLen = 10 # generate lists of length 10
low = 0 # the lower bound of the numbers you want to walk
high = random.randint(0,100) # the upper bound of the numbers you want to walk
for L in itertools.product(range(low, high+1), repeat=listLen):
  print(L)

你需要更清楚地解释这一点。列表中是否填写了
0
s?多少?@jozzas,里面装的物品数量是固定的。每个列表将包含N个0,其中N等于1或更大。这是一个可能的家庭作业,似乎没有人努力解决它。尝试一些解决方案,如果有的话,问一些更具体的问题。我相信他希望每次你重置设备时使用不同的随机数。你写的只是在开头选一个。@Bakuriu:hrm。。。说得好。检查编辑!呵呵呵呵这太多了win@inspectorG4dget是的,我一直在等待倒计时结束,直到我能接受为止it@ILovePython:不用担心!我几乎总是把这条评论发布给有
listLen = 10
low = 0
for L in itertools.product(*[range(low,random.randint(0,100)) for _ in range(listLen)]):
  print(L)