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 = ""
)
| 614 | |
| 615 | |
| 616 | def 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]) |
no outgoing calls
no test coverage detected
searching dependent graphs…