From 6ff2023a206d51111e55fec2fad84abae26eadd5 Mon Sep 17 00:00:00 2001 From: Hussain Nagaria Date: Sun, 17 Dec 2023 17:02:42 +0530 Subject: [PATCH] docs: comma_sep --- frappe/utils/data.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/frappe/utils/data.py b/frappe/utils/data.py index 8973a8ff55..420cd69e02 100644 --- a/frappe/utils/data.py +++ b/frappe/utils/data.py @@ -1719,6 +1719,12 @@ def comma_and(some_list: list | tuple, add_quotes=True) -> str: def comma_sep(some_list: list | tuple, pattern: str, add_quotes=True) -> str: + """Returns the given list or tuple as a comma separated string, with the last item joined by the given string format pattern. + + If `add_quotes` is True, each item in the list will be wrapped in single quotes. + + e.g. if `some_list` is ['a', 'b', 'c'] and `pattern` is '{0} or {1}', the output will be 'a, b or c' + """ if isinstance(some_list, (list, tuple)): # list(some_list) is done to preserve the existing list some_list = [str(s) for s in list(some_list)]