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
#1
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 Huh

Any suggestions would be very much appreciated.

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  Help with Python Script to generate SVG Dot Matrix Pattern for LED Light Guide iamrickm 2 709 Aug-25-2023, 06:07 PM
Last Post: iamrickm
  Delete strings from a list to create a new only number list Dvdscot 8 1,466 May-01-2023, 09:06 PM
Last Post: deanhystad
  [split] why can't i create a list of numbers (ints) with random.randrange() astral_travel 7 1,454 Oct-23-2022, 11:13 PM
Last Post: Pedroski55
  how to easily create a list of already existing item CompleteNewb 15 3,386 Jan-06-2022, 12:48 AM
Last Post: CompleteNewb
  Create SQLite columns from a list or tuple? snakes 6 8,524 May-04-2021, 12:06 PM
Last Post: snakes
  Create variable and list dynamically quest_ 12 4,290 Jan-26-2021, 07:14 PM
Last Post: quest_
  How to create a linked list and call it? loves 12 4,389 Nov-22-2020, 03:50 PM
Last Post: loves
  Remove specific elements from list with a pattern Xalagy 3 2,623 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 1,989 Aug-14-2020, 12:37 PM
Last Post: Yoriz
  How to define a function to create a resorted list? sparkt 6 2,741 Aug-08-2020, 04:10 PM
Last Post: sparkt

Forum Jump:

User Panel Messages

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