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
additional argument for str.join() #87446
Comments
It would be nice to have an additional argument for str.join() so this ", ".join(["a", "b", "c"], ", and ") would output "a, b, and, c" |
This seems like a very specific use case. Too specific IMO for a method on all string objects for anyone using Python anywhere in the world. Why not just write a function like this? def my_join(strings, sep=", ", last_sep=", and "):
strings = list(strings)
return sep.join(strings[:-1]) + last_sep + strings[-1] >>> my_join(["one", "two", "three"])
'one, two, and three' |
Python 3.9 is in feature freeze, this couldn't be added before 3.10 now. You have:
outputing this: "a, b, and, c" So what are the semantics of this additional argument? To insert it before the last item? |
Looking more closely, I think that the semantics are to concatenate the extra argument to the second-last item:
which would be the same as:
I'm not sure how this is useful. In English, there should never be a comma after the "and", and there possibly shouldn't be a comma after the "b" either, depending on context.
See the Oxford or serial comma: https://thegrammargirls.wordpress.com/tag/oxford-comma/ I'm going to close this feature request. It's too specific and the semantics don't seem to be very useful. But if you would still like to propose this, or a similar change, please discuss it first either on the Python-Ideas mailing list:
or at the Ideas topic on
so that we can determine the required semantics and get a sense for how useful it would be in general. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: