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

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


output of my code :

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


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

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.