feat: Add ljust_list utility method

This commit is contained in:
Suraj Shetty 2020-03-31 13:35:11 +05:30
parent 5deb86f46c
commit 5f5ab02260

View file

@ -67,3 +67,18 @@ def find_all(list_of_dict, match_function):
if match_function(entry):
found.append(entry)
return found
def ljust_list(_list, length, fill_word=None):
'''Similar to ljust but for list
Usage:
$ ljust_list([1, 2, 3], 5)
> [1, 2, 3, None, None]
'''
# make a copy to avoid mutation of passed list
_list = list(_list)
fill_length = length - len(_list)
if fill_length > 0:
_list.extend([fill_word] * fill_length)
return _list