Convert int to list in python
<p>Take a list, say for example this one:</p>

<pre><code>a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
</code></pre>

<p>and write a program that prints out all the elements of the list as the list [1,1,2,3,5] that are less than 5.
Currently it prints as </p>

<pre><code>1
1
2
3
5
</code></pre>

<p>My code </p>

<pre><code>a = [1,1,2,3,5,8,13,21,34,55,89]
count = 0
for i in a:
    if i&lt;=5:
        count+=1
        print(i)
</code></pre>

<p>To have it print out as a list, keep it as a list.  You can use list comprehension to accomplish this:</p>

<pre><code>&gt;&gt;&gt; a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
&gt;&gt;&gt; [i for i in a if i&lt;=5]
[1, 1, 2, 3, 5]
</code></pre>

<p>If we use <code>print</code>, it still looks the same:</p>

<pre><code>&gt;&gt;&gt; print([i for i in a if i&lt;=5])
[1, 1, 2, 3, 5]
</code></pre>

python