Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to format a list with commas and a final 'and'/'or' #322

Open
lordmauve opened this issue Dec 23, 2022 · 0 comments
Open

Function to format a list with commas and a final 'and'/'or' #322

lordmauve opened this issue Dec 23, 2022 · 0 comments

Comments

@lordmauve
Copy link

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'
@lordmauve 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant