I have this code:
symbolslist = [\"100\",\"200\",\"300\",\"400\",\"500\",\"600\",\"700\",\"800\",\"900\",\"1000\",\"1500\",\"2000\",\"3000\",\"4000\",\"5000\",\"
Your pricelist
variable is being overwritten on each iteration of the loop. You need to store your result in a data structure of some sort, such as a list
(and a list
will work with the [0:20]
slice notation you wish to use):
symbolslist = ["100","200","300","400","500","600","700","800","900","1000","1500","2000","3000","4000","5000","7000","10000"]
pricelist = [] #empty list
i=0
while i
Now you can do:
pricelist[0:20] #returns members 0 to 19 of pricelist
Just like you wanted.
I also suggest using a for
loop instead of manually incrementing your counter in a while
loop.
Python 2:
for i in xrange(len(symbolslist)):
Python 3:
for i in range(len(symbolslist)):
#xrange will also work in Python 3, but it's just there to
#provide backward compatibility.
If you do it this way you can omit the i+=1
line at the end.