Matrix in python with a set column
<p>So I'm trying to make a 2x3 matrix with the output </p>

<pre><code>    &gt;&gt;&gt;l([1980, 1981, 1982])
    &gt;&gt;&gt;[[1., 1980], [1., 1981], [1.,1982]]
</code></pre>

<p>However the output I'm getting is:</p>

<pre><code>    &gt;&gt;&gt;l([1980, 1981, 1982])
    &gt;&gt;&gt;[1.0, [1980, 1981, 1982]]
</code></pre>

<p>my code is:</p>

<pre><code>def l(x):   
    for i in range(len(x)):
        xl  = [1., x]
    return xl
</code></pre>

<p>I know I have to reiterate it multiple times using a for loop, but I'm not entirely sure how to do it.</p>

<p>You can use <code>map</code> also:</p>

<pre><code>&gt;&gt;&gt; li=[1980, 1981, 1982]
&gt;&gt;&gt; map(lambda e: [1.0]+[e], li)
[[1.0, 1980], [1.0, 1981], [1.0, 1982]]
</code></pre>

<p>Or, if you don't mind a list of tuples:</p>

<pre><code>&gt;&gt;&gt; zip((1.0,)*len(li),li)
[(1.0, 1980), (1.0, 1981), (1.0, 1982)]
</code></pre>

<p>Or, if you want to fix yours:</p>

<pre><code>&gt;&gt;&gt; li2=[]
&gt;&gt;&gt; for e in li:
...    li2.append([1.0,e])
... 
&gt;&gt;&gt; li2
[[1.0, 1980], [1.0, 1981], [1.0, 1982]]
</code></pre>

python list matrix