Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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中列表中的枚举项集_Python - Fatal编程技术网

Python中列表中的枚举项集

Python中列表中的枚举项集,python,Python,我需要创建许多数字集。我将我的输出和我需要的输出相加。 我编写了列表的第一个项目输出,然后我需要对所有项目使用相同的输出 a = [1, 2, 3, 4, 5, 6, 7, 8] for index, item in enumerate(a): index_0 = index index_1 = index + 1 index_2 = index + 2 index_3 = index + 3 print((a[index_0], a[index_1],

我需要创建许多数字集。我将我的输出和我需要的输出相加。 我编写了列表的第一个项目输出,然后我需要对所有项目使用相同的输出

a = [1, 2, 3, 4, 5, 6, 7, 8]
for index, item in enumerate(a):
    index_0 = index
    index_1 = index + 1
    index_2 = index + 2
    index_3 = index + 3
    print((a[index_0], a[index_1], a[index_2], a[index_3]))
>>>
1, 2, 3, 4
2, 3, 4, 5
3, 4, 5, 6
4, 5, 6, 7
5, 6, 7, 8
我在为每一项寻找什么:

1,2,3,4
1,2,3,5
1,2,3,6
1,2,3,7
1,2,3,8
1,2,4,5
1,2,4,6
1,2,4,7
1,2,4,8
1,2,5,6
1,2,5,7
1,2,5,8
1,2,6,7
1,2,6,8
1,2,7,8
1,3,4,5
1,3,4,6
1,3,4,7
1,3,4,8
1,3,5,6
1,3,5,7
1,3,5,8
1,3,6,7
1,3,6,8
1,3,7,8
1,4,5,6
1,4,5,7
1,4,5,8
1,4,6,7
1,4,6,8
1,4,7,8
1,5,6,7
1,5,7,8
1,6,7,8
您是否希望使用itertools组合:

输出:

[(1, 2, 3, 4),
 (1, 2, 3, 5),
 (1, 2, 3, 6),
 (1, 2, 3, 7),
 (1, 2, 3, 8),
 (1, 2, 4, 5),
 (1, 2, 4, 6),
 (1, 2, 4, 7),
 (1, 2, 4, 8),
 (1, 2, 5, 6),
 (1, 2, 5, 7),
 (1, 2, 5, 8),
 (1, 2, 6, 7),
 (1, 2, 6, 8),
 (1, 2, 7, 8),
 (1, 3, 4, 5),
 (1, 3, 4, 6),
 (1, 3, 4, 7),
 (1, 3, 4, 8),
 (1, 3, 5, 6),
 (1, 3, 5, 7),
 (1, 3, 5, 8),
 (1, 3, 6, 7),
 (1, 3, 6, 8),
 (1, 3, 7, 8),
 (1, 4, 5, 6),
 (1, 4, 5, 7),
 (1, 4, 5, 8),
 (1, 4, 6, 7),
 (1, 4, 6, 8),
 (1, 4, 7, 8),
 (1, 5, 6, 7),
 (1, 5, 6, 8),
 (1, 5, 7, 8),
 (1, 6, 7, 8),
 (2, 3, 4, 5),
 (2, 3, 4, 6),
 (2, 3, 4, 7),
 (2, 3, 4, 8),
 (2, 3, 5, 6),
 (2, 3, 5, 7),
 (2, 3, 5, 8),
 (2, 3, 6, 7),
 (2, 3, 6, 8),
 (2, 3, 7, 8),
 (2, 4, 5, 6),
 (2, 4, 5, 7),
 (2, 4, 5, 8),
 (2, 4, 6, 7),
 (2, 4, 6, 8),
 (2, 4, 7, 8),
 (2, 5, 6, 7),
 (2, 5, 6, 8),
 (2, 5, 7, 8),
 (2, 6, 7, 8),
 (3, 4, 5, 6),
 (3, 4, 5, 7),
 (3, 4, 5, 8),
 (3, 4, 6, 7),
 (3, 4, 6, 8),
 (3, 4, 7, 8),
 (3, 5, 6, 7),
 (3, 5, 6, 8),
 (3, 5, 7, 8),
 (3, 6, 7, 8),
 (4, 5, 6, 7),
 (4, 5, 6, 8),
 (4, 5, 7, 8),
 (4, 6, 7, 8),
 (5, 6, 7, 8)]

你们是在寻找一个数字的每四个长度的组合吗?如果不是的话,那么你的问题必须更具描述性。我还希望您认识到set在Python中是一个保留字,您的代码没有使用这种类型的东西,这让人们感到不舒服。是的!谢谢如果我想在数字之间加一个限制,例如,最大10个微分值,比如:1,2,3,4,最大值是1,2,3,10,下一个是1,2,4,5,最大值是1,2,4,10。。。怎么做?
[(1, 2, 3, 4),
 (1, 2, 3, 5),
 (1, 2, 3, 6),
 (1, 2, 3, 7),
 (1, 2, 3, 8),
 (1, 2, 4, 5),
 (1, 2, 4, 6),
 (1, 2, 4, 7),
 (1, 2, 4, 8),
 (1, 2, 5, 6),
 (1, 2, 5, 7),
 (1, 2, 5, 8),
 (1, 2, 6, 7),
 (1, 2, 6, 8),
 (1, 2, 7, 8),
 (1, 3, 4, 5),
 (1, 3, 4, 6),
 (1, 3, 4, 7),
 (1, 3, 4, 8),
 (1, 3, 5, 6),
 (1, 3, 5, 7),
 (1, 3, 5, 8),
 (1, 3, 6, 7),
 (1, 3, 6, 8),
 (1, 3, 7, 8),
 (1, 4, 5, 6),
 (1, 4, 5, 7),
 (1, 4, 5, 8),
 (1, 4, 6, 7),
 (1, 4, 6, 8),
 (1, 4, 7, 8),
 (1, 5, 6, 7),
 (1, 5, 6, 8),
 (1, 5, 7, 8),
 (1, 6, 7, 8),
 (2, 3, 4, 5),
 (2, 3, 4, 6),
 (2, 3, 4, 7),
 (2, 3, 4, 8),
 (2, 3, 5, 6),
 (2, 3, 5, 7),
 (2, 3, 5, 8),
 (2, 3, 6, 7),
 (2, 3, 6, 8),
 (2, 3, 7, 8),
 (2, 4, 5, 6),
 (2, 4, 5, 7),
 (2, 4, 5, 8),
 (2, 4, 6, 7),
 (2, 4, 6, 8),
 (2, 4, 7, 8),
 (2, 5, 6, 7),
 (2, 5, 6, 8),
 (2, 5, 7, 8),
 (2, 6, 7, 8),
 (3, 4, 5, 6),
 (3, 4, 5, 7),
 (3, 4, 5, 8),
 (3, 4, 6, 7),
 (3, 4, 6, 8),
 (3, 4, 7, 8),
 (3, 5, 6, 7),
 (3, 5, 6, 8),
 (3, 5, 7, 8),
 (3, 6, 7, 8),
 (4, 5, 6, 7),
 (4, 5, 6, 8),
 (4, 5, 7, 8),
 (4, 6, 7, 8),
 (5, 6, 7, 8)]