feat: Add ljust_list utility method
This commit is contained in:
parent
5deb86f46c
commit
5f5ab02260
1 changed files with 15 additions and 0 deletions
|
|
@ -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
|
||||
Loading…
Add table
Reference in a new issue