title: Scale a column of a list-of-lists in Python
body: <p>If I have a matrix as a simple array of arrays (not a numpy matrix), how could I scale one column of the matrix in just one line of code? </p>
  
  <p>This is just out of curiosity - I'm not claiming there's any benefit to one line over two or three.</p>
  
  <p>Here's what I have, for some matrix "mtx", column index "index" and scalar "scale". Can we make it prettier or more readable? Also, this could fail if multiple columns have the same values.</p>
  
  <pre><code>mtx = zip( * ( (map(lambda r : r*scale if zip(*mtx).index(col)==index else r, col)) for col in zip(*mtx)] ) )
  </code></pre>
  
  <p>Edit: </p>
  
  <p>here's an example of input/out, as requested</p>
  
  <pre><code>mtx = [ [ i for i in range(3) ] for j in range(3) ]
  index = 1
  scale = 17
  print mtx
  
  mtx = zip( * ( p (map(lambda r : r*scale if zip(*mtx).index(col)==index else r, col)) for col in zip(*mtx)] ) )
  print mtx
  </code></pre>
  
  <p>The print statements will produce, respectively:</p>
  
  <pre><code>--&gt; [ [0,1,2],[0,1,2],[0,1,2] ]
  --&gt; [ [0,17,2],[0,17,2],[0,17,2] ]
  </code></pre>