I have a nested list which contains lists filled with strings. What I am trying to do is make each list in this nest the same length as the longest available list in that n
The expression 'null' * (len(maxSS7) - len(row))
creates one potentially very long string.
Use
row.extend('null' for _ in xrange(maxSS7 - len(row)))
instead. The generator expression lets you avoid creating an extra list object just to extend row
.
>>> ['null' * 2]
['nullnull']
>>> ['null' for _ in xrange(2)]
['null', 'null']
But the .extend
call itself is never reached, as you if
statement is testing the wrong thing; change it to:
if len(row) < maxSS7:
maxSS7
is aready a number (the length of the longest list); asking that number for it's length is not what you were looking for.