Bottom Page

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

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Create a dictionary from a list klllmmm 3 173 Oct-06-2019, 05:50 PM
Last Post: Gribouillis
  How to create a list with all values being zero 357mag 4 280 Jul-14-2019, 03:43 PM
Last Post: ThomasL
  Create new list from another list based on condition khalidreemy 1 319 Jun-11-2019, 10:21 AM
Last Post: buran
  How to create meshgrid with non-integer stepsize of list elements? dazzabaijan 1 374 Mar-11-2019, 02:00 AM
Last Post: ichabod801
  modify line in file if pattern found in list. kttan 1 460 Dec-10-2018, 08:45 AM
Last Post: Gribouillis
  Python and strategy pattern tanc 5 688 Nov-30-2018, 08:55 AM
Last Post: Gribouillis
  Create a List for Boolean Mask. leoahum 4 699 Oct-09-2018, 02:38 PM
Last Post: leoahum
  Create Alert if string from list appears on other list javalava 1 486 Sep-17-2018, 02:44 PM
Last Post: DeaD_EyE
  Parsing Text file having repeated value key pair using python manussnair 3 656 Aug-04-2018, 11:48 PM
Last Post: micseydel
  code pattern to test if list has all the same Skaperen 5 916 Jul-25-2018, 06:09 AM
Last Post: buran

Forum Jump:


Users browsing this thread: 1 Guest(s)