Skip to main content

Equalizing lists's length using Python

Assuming you're having a list of lists which vary in length and you want to make every list have the same length (with the length of the longest list). One simple solution is to append the children lists with empty strings or None. For example:

[[1,2], [4,5,6], [6,7,8,9,10]]


[[1,2, '', '', ''], [4,5,6, '', ''], [6,7,8,9,10]]

Solution #1 - Here is the snippet: