I've just started playing around with python lists, I've written the simple code below expecting the printed file to display the numbers [12,14,16,18,20,22] but only 22 is displayed. Any help would be great.
a=10
b=14
while a <= 20:
a=a+2
b=b-1
datapoints=[]
datapoints.insert(0,a)
print datapoints
datapointsto an empty list in the loop. I suggest you move thedatapoints=[]line to take place outside of the loop.list.append()if you expected numbers to be added at the end, which your expected output suggests you want.bhave a purpose?collections.dequeso you can callappendleftand perform the prepend efficiently (lists only have efficient appends on the right, prepending isO(n)).whileis often not that pythonic IMO for a case like this, consider using aforloop instead in combination withrange