Adding data to a Python list
<p>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.</p>

<pre><code>a=10
b=14
while a &lt;= 20:
    a=a+2
    b=b-1
    datapoints=[]
    datapoints.insert(0,a)
print datapoints
</code></pre>

<p>Joel already answered but if you want a more compact code you can use range</p>

<pre><code>numbers = []
for number in range(12,24,2):
    # do whatevery you want with b
    numbers.append(number)

print numbers
</code></pre>

<p>or if you only want to print the numbers you can do</p>

<pre><code>print [number for number in range(12,24,2)]
</code></pre>

python python-2.7