Python Forum
create list from repeated pattern in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
create list from repeated pattern in python
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 Huh

Any suggestions would be very much appreciated.

Many thanks,
You could use list comprehension
L = [pattern(i) for i in range(n)]
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


## use a while instead of this for and exit
## when the condition is met
for ctr in range(10):
    for ctr_2 in range(5):
        inner_ctr += 1
    a_list.append((ctr+1, tuple(sub_list)))


Possibly Related Threads…
Thread Author Replies Views Last Post
  Create SQLite columns from a list or tuple? snakes 6 491 May-04-2021, 12:06 PM
Last Post: snakes
  Create variable and list dynamically quest_ 12 685 Jan-26-2021, 07:14 PM
Last Post: quest_
  How to create a linked list and call it? loves 12 921 Nov-22-2020, 03:50 PM
Last Post: loves
  Remove specific elements from list with a pattern Xalagy 3 681 Oct-11-2020, 07:18 AM
Last Post: Xalagy
  How to create and define in one line a 2D list of class objects in Python T2ioTD 1 470 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  How to define a function to create a resorted list? sparkt 6 789 Aug-08-2020, 04:10 PM
Last Post: sparkt
  Create a program that PING a list of IPs skaailet 7 1,149 Mar-26-2020, 10:46 PM
Last Post: snippsat
  How to tabulate correctly repeated blocks? Xiesxes 4 966 Mar-21-2020, 04:57 PM
Last Post: Xiesxes
  Create a list of co-ordinates from Mouse press events Jagruthi 0 521 Mar-12-2020, 08:46 AM
Last Post: Jagruthi
  create a list of object with a list of character studenthch 0 505 Feb-12-2020, 08:43 AM
Last Post: studenthch

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020