MCPcopy Index your code
hub / github.com/ipython/ipython / get_text_list

Function get_text_list

IPython/utils/text.py:616–648  ·  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_: List[str], last_sep: str = " and ", sep: str = ", ", wrap_item_with: str = ""
)

Source from the content-addressed store, hash-verified

614
615
616def get_text_list(
617 list_: List[str], last_sep: str = " and ", sep: str = ", ", wrap_item_with: str = ""
618) -> str:
619 """
620 Return a string with a natural enumeration of items
621
622 >>> get_text_list(['a', 'b', 'c', 'd'])
623 'a, b, c and d'
624 >>> get_text_list(['a', 'b', 'c'], ' or ')
625 'a, b or c'
626 >>> get_text_list(['a', 'b', 'c'], ', ')
627 'a, b, c'
628 >>> get_text_list(['a', 'b'], ' or ')
629 'a or b'
630 >>> get_text_list(['a'])
631 'a'
632 >>> get_text_list([])
633 ''
634 >>> get_text_list(['a', 'b'], wrap_item_with="`")
635 '`a` and `b`'
636 >>> get_text_list(['a', 'b', 'c', 'd'], " = ", sep=" + ")
637 'a + b + c = d'
638 """
639 if len(list_) == 0:
640 return ''
641 if wrap_item_with:
642 list_ = ['%s%s%s' % (wrap_item_with, item, wrap_item_with) for
643 item in list_]
644 if len(list_) == 1:
645 return list_[0]
646 return '%s%s%s' % (
647 sep.join(i for i in list_[:-1]),
648 last_sep, list_[-1])

Callers 1

loadMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…