By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,994 Members | 1,166 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,994 IT Pros & Developers. It's quick & easy.

Increment of array/list element

P: 20
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-


Expand|Select|Wrap|Line Numbers
  1. a=[0 for i in range(18)]
  2. for i in range(6):
  3.     a[i]=i
Oct 4 '10 #1
Share this Question
Share on Google+
1 Reply


bvdet
Expert Mod 2.5K+
P: 2,851
Expand|Select|Wrap|Line Numbers
  1. a=[0 for i in range(18)]
  2. pos = 0
  3. for j in range(3):
  4.     for i in range(6):
  5.         a[i+pos]=i
  6.     pos += 6
Expand|Select|Wrap|Line Numbers
  1. a1 = [i for i in range(6)]
  2. a1 *= 3
Oct 4 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.