From 5f5ab02260b39ad6ef724e94cd8f2e5ab0fa7daf Mon Sep 17 00:00:00 2001 From: Suraj Shetty Date: Tue, 31 Mar 2020 13:35:11 +0530 Subject: [PATCH] feat: Add ljust_list utility method --- frappe/core/utils.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/frappe/core/utils.py b/frappe/core/utils.py index 55767ffe34..abab9e6160 100644 --- a/frappe/core/utils.py +++ b/frappe/core/utils.py @@ -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 \ No newline at end of file