You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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'
The text was updated successfully, but these errors were encountered:
lordmauve
changed the title
Function to print a list with commas and a final 'and'/'or'
Function to format a list with commas and a final 'and'/'or'
Dec 23, 2022
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.
The text was updated successfully, but these errors were encountered: