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_ |
|
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' |
|
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 |
|
757 | return '%s%s%s' % ( | |
754 |
|
|
758 | sep.join(i for i in list_[:-1]), | |
755 |
last_ |
|
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