-
Notifications
You must be signed in to change notification settings - Fork 362
Open
Description
A function that I frequently want is to print a list of strings, separating them with commas, plus a final conjunction like 'and' or 'or'. The Oxford comma should be the default but some users might like to disable it.
>>> human_list(['spam'])
'spam'
>>> human_list(['egg', 'spam'])
'egg and spam'
>>> human_list(['egg', 'bacon', 'spam'], conjunction='or')
'egg, bacon, or spam'
>>> human_list(['spam', 'spam', 'egg', 'bacon', 'spam'])
'spam, spam, egg, bacon, and spam'
>>> human_list(['lobster thermidor aux crevettes', 'garnished with truffle paté', 'with a fried egg on top', 'spam'], oxford=False)
'lobster thermidor aux crevettes, garnished with truffle paté, with a fried egg on top and spam'
Metadata
Metadata
Assignees
Labels
No labels