Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.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_Python 3.x_List_Tuples - Fatal编程技术网

在python中从重复模式创建列表

在python中从重复模式创建列表,python,python-3.x,list,tuples,Python,Python 3.x,List,Tuples,我想在python3中创建一个列表,如下所示: L = [(0,(0,1,2,3,4)), (1, (5,6,7,8,9)),(2,(10,11,12,13,14))......) 我们把它叫做L=[i,j1,j2,j3,j4,j5 重要的是,模式不断重复,直到j5达到740231 如果您有任何建议,我们将不胜感激。这里有一个使用枚举和范围的解决方案: 另一方面,严格理解: L = [(i,tuple(range(i*5,i*5+5))) for i in range(740231//5+1)

我想在python3中创建一个列表,如下所示:

L = [(0,(0,1,2,3,4)), (1, (5,6,7,8,9)),(2,(10,11,12,13,14))......)
我们把它叫做L=[i,j1,j2,j3,j4,j5

重要的是,模式不断重复,直到j5达到740231

如果您有任何建议,我们将不胜感激。

这里有一个使用枚举和范围的解决方案:


另一方面,严格理解:

L = [(i,tuple(range(i*5,i*5+5))) for i in range(740231//5+1)]

使用发电机功能:

def gen():
   x = 0
   y = 0  
   while y < 740231:
       yield( (x, tuple(range(y,y+5)), ) )
       x += 1
       y += 5
def gen():
   x = 0
   y = 0  
   while y < 740231:
       yield( (x, tuple(range(y,y+5)), ) )
       x += 1
       y += 5
>>> list(gen())
[(0, (0, 1, 2, 3, 4)), (1, (5, 6, 7, 8, 9)), (2, (10, 11, 12, 13, 14)) ... ]