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>What you want is </p>

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

<p>Or, since there is no need to use the index <code>i</code> for anything other than indexing the elements of <code>x</code>, you can use:</p>

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

<p>Or you can simply compress all of this into a list concatenation as in Tim's answer:</p>

<pre><code>def l(x):
    return [[1., e] for e in x]       
</code></pre>

python list matrix