Increment of array/list element

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • peachdot
    New Member
    • Aug 2010
    • 20

    Increment of array/list element

    hi,

    i want to create an array element of increment value in a loop.

    example:
    a=[0,1,2,3,4,5,0,1 ,2,3,4,5,0,1,2, 3,4,5]

    output of my code :
    a=[0,1,2,3,4,5,0,0 ,0,0,0,0,0,0,0, 0,0,0]

    how do i fill in the rest of the array element?help!

    thanks-


    Code:
    a=[0 for i in range(18)]
    for i in range(6):
    	a[i]=i
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Code:
    a=[0 for i in range(18)]
    pos = 0
    for j in range(3):
        for i in range(6):
            a[i+pos]=i
        pos += 6
    Code:
    a1 = [i for i in range(6)]
    a1 *= 3

    Comment

    Working...