Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 置换中间数组长度为M的N个列表的所有可能性_Python_List_Random_Size_Permutation - Fatal编程技术网

Python 置换中间数组长度为M的N个列表的所有可能性

Python 置换中间数组长度为M的N个列表的所有可能性,python,list,random,size,permutation,Python,List,Random,Size,Permutation,我想刻一些文件。为了做到这一点,我想排列所有可能的。有3个可能的开始,40个可能的中间块和3个可能的结束 问题是我们不知道中间的街区有多长。它可能有1个街区长,但也有40个街区长。我们唯一能确定的是,这些块是连续出现的,因为我正在尝试恢复PNG 我已经尝试过用很多for循环手工编写代码,但至今没有成功。 我确实尝试了以下代码 s= [[headersList],[idatList],[iendList]] print(list(itertools.product(*s))) 我希望输出

我想刻一些文件。为了做到这一点,我想排列所有可能的。有3个可能的开始,40个可能的中间块和3个可能的结束

问题是我们不知道中间的街区有多长。它可能有1个街区长,但也有40个街区长。我们唯一能确定的是,这些块是连续出现的,因为我正在尝试恢复PNG

我已经尝试过用很多for循环手工编写代码,但至今没有成功。 我确实尝试了以下代码

s= [[headersList],[idatList],[iendList]]
    print(list(itertools.product(*s)))
我希望输出是这样的

[1, [1], 1]
[1, [1,2] , 1]
[1, [1,2,3], 1]
...
[2, [1] ,1]
[2, [1, 2], 1]
等等。
唯一的条件是开始和结束块必须位于数组的相应开始和结束位置。中间块的大小必须连续为1到最大40。

以下是您应该如何使用产品:

from itertools import product

head   = range(1,4)
tail   = range(1,4)
middle = range(1,41)
combos = [(h,list(range(1,m+1)),t) for t,h,m in product(tail,head,middle)]


print(combos)
# [(1, [1], 1), (1, [1, 2], 1), (1, [1, 2, 3], 1), 
#  (1, [1, 2, 3, 4], 1), (1, [1, 2, 3, 4, 5], 1), ...

你能给出一个样本输入和相应样本输出的具体例子吗?你能澄清1,2,7是否有效吗?我想这是无效的。是否应该始终以1开头?3,4,5是一个有效的中间块吗?然后你只有40个中间组合,并且你试图生成的总共3x40x3=360个排列。@GreenCoveGuy这是一个十六进制数据文件,所以在这里发布它相当长。它应该是一个PNG块、N idat块和一个iend块。@EmmetB第一个和最后一个数字应该在1和3之间。因为有3个起始块和3个结束块。中间块为N长,最大长度为40。我所知道的是中间块中的数字连续出现。