##// END OF EJS Templates
generalizing get_text_list helper
Martín Gaitán -
Show More
@@ -726,15 +726,17 b" def columnize(items, separator=' ', displaywidth=80):"
726 return '\n'.join(map(sjoin, fmatrix))+'\n'
726 return '\n'.join(map(sjoin, fmatrix))+'\n'
727
727
728
728
729 def get_text_list(list_, last_word='and', wrap_item_with=""):
729 def get_text_list(list_, last_sep=' and ', sep=", ", wrap_item_with=""):
730 """
730 """
731 Return a string with a natural enumeration of items
731 Return a string with a natural enumeration of items
732
732
733 >>> get_text_list(['a', 'b', 'c', 'd'])
733 >>> get_text_list(['a', 'b', 'c', 'd'])
734 'a, b, c and d'
734 'a, b, c and d'
735 >>> get_text_list(['a', 'b', 'c'], 'or')
735 >>> get_text_list(['a', 'b', 'c'], ' or ')
736 'a, b or c'
736 'a, b or c'
737 >>> get_text_list(['a', 'b'], 'or')
737 >>> get_text_list(['a', 'b', 'c'], ', ')
738 'a, b, c'
739 >>> get_text_list(['a', 'b'], ' or ')
738 'a or b'
740 'a or b'
739 >>> get_text_list(['a'])
741 >>> get_text_list(['a'])
740 'a'
742 'a'
@@ -742,6 +744,8 b' def get_text_list(list_, last_word=\'and\', wrap_item_with=""):'
742 ''
744 ''
743 >>> get_text_list(['a', 'b'], wrap_item_with="`")
745 >>> get_text_list(['a', 'b'], wrap_item_with="`")
744 '`a` and `b`'
746 '`a` and `b`'
747 >>> get_text_list(['a', 'b', 'c', 'd'], " = ", sep=" + ")
748 'a + b + c = d'
745 """
749 """
746 if len(list_) == 0:
750 if len(list_) == 0:
747 return ''
751 return ''
@@ -750,6 +754,6 b' def get_text_list(list_, last_word=\'and\', wrap_item_with=""):'
750 item in list_]
754 item in list_]
751 if len(list_) == 1:
755 if len(list_) == 1:
752 return list_[0]
756 return list_[0]
753 return '%s %s %s' % (
757 return '%s%s%s' % (
754 ', '.join(i for i in list_[:-1]),
758 sep.join(i for i in list_[:-1]),
755 last_word, list_[-1]) No newline at end of file
759 last_sep, list_[-1]) No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now