Equating the lengths of the arrays in an array of arrays
<p>Given an array of arrays with different lengths. Is there a cleaner (shorter) way to equate the lengths of the arrays by filling the shorter ones with zeros other than the following code:</p>

<pre><code>a = [[1.0, 2.0, 3.0, 4.0],[2.0, 3.0, 1.0],[5.0, 5.0, 5.0, 5.0],[1.0, 1.0]]


max =0
for x in a:
    if len(x) &gt; max:
        max = len(x)

print max
new = []
for x in a:
    if len(x)&lt;max:
        x.extend([0.0]* (max-len(x)) )
    new.append(x)

print new
</code></pre>

<pre><code>In: b = [i+[0.]*(max(map(len,a))-len(i)) for i in a]

In: b
Out: 
[[1.0, 2.0, 3.0, 4.0],
 [2.0, 3.0, 1.0, 0.0],
 [5.0, 5.0, 5.0, 5.0],
 [1.0, 1.0, 0.0, 0.0]]
</code></pre>

python