create list from repeated pattern in python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: create list from repeated pattern in python (/thread-13044.html) |
create list from repeated pattern in python - Code4fun - Sep-25-2018 Hello, I would like to create a list in Python3, which look like this L = [(0,(0,1,2,3,4)), (1, (5,6,7,8,9)),(2,(10,11,12,13,14))......)lets call it L= [(i,(j1,j2,j3,j4,j5),...)The important is that the pattern keep on repeating till the j5 reaches 740231 Any suggestions would be very much appreciated. Many thanks, RE: create list from repeated pattern in python - Gribouillis - Sep-25-2018 You could use list comprehension L = [pattern(i) for i in range(n)] RE: create list from repeated pattern in python - woooee - Sep-25-2018 Quote:L = [(0,(0,1,2,3,4)), (1, (5,6,7,8,9)),(2,(10,11,12,13,14))......) I'm not going to go all the way out to 740 thousand, but it is a simple set of fors import pprint a_list=[] inner_ctr=1 ## use a while instead of this for and exit ## when the condition is met for ctr in range(10): sub_list=[] for ctr_2 in range(5): sub_list.append(inner_ctr) inner_ctr += 1 a_list.append((ctr+1, tuple(sub_list))) pprint.pprint(a_list) |