MCPcopy Create free account
hub / github.com/ipython/ipython / get_text_list

Function get_text_list

IPython/utils/text.py:742–772  ·  view source on GitHub ↗

Return a string with a natural enumeration of items >>> get_text_list(['a', 'b', 'c', 'd']) 'a, b, c and d' >>> get_text_list(['a', 'b', 'c'], ' or ') 'a, b or c' >>> get_text_list(['a', 'b', 'c'], ', ') 'a, b, c' >>> get_text_list(['a', 'b'], ' or ') 'a or b'

(list_, last_sep=' and ', sep=", ", wrap_item_with="")

Source from the content-addressed store, hash-verified

740
741
742def get_text_list(list_, last_sep=' and ', sep=", ", wrap_item_with=""):
743 """
744 Return a string with a natural enumeration of items
745
746 >>> get_text_list(['a', 'b', 'c', 'd'])
747 'a, b, c and d'
748 >>> get_text_list(['a', 'b', 'c'], ' or ')
749 'a, b or c'
750 >>> get_text_list(['a', 'b', 'c'], ', ')
751 'a, b, c'
752 >>> get_text_list(['a', 'b'], ' or ')
753 'a or b'
754 >>> get_text_list(['a'])
755 'a'
756 >>> get_text_list([])
757 ''
758 >>> get_text_list(['a', 'b'], wrap_item_with="`")
759 '`a` and `b`'
760 >>> get_text_list(['a', 'b', 'c', 'd'], " = ", sep=" + ")
761 'a + b + c = d'
762 """
763 if len(list_) == 0:
764 return ''
765 if wrap_item_with:
766 list_ = ['%s%s%s' % (wrap_item_with, item, wrap_item_with) for
767 item in list_]
768 if len(list_) == 1:
769 return list_[0]
770 return '%s%s%s' % (
771 sep.join(i for i in list_[:-1]),
772 last_sep, list_[-1])

Callers 1

loadMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected