Last active
March 26, 2021 07:52
-
-
Save Willy-JL/89edabcbd0a7df09a8a4666bfb79db0c to your computer and use it in GitHub Desktop.
Join words in a speech-like manner
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
example = ["abc", "def", "ghi"] | |
def join_words(words): | |
return (", ".join(words[:-1]) + (" and " if len(words) > 1 else "") + words[-1]) if len(words) > 0 else "" | |
result = join_words(example) | |
print(result) | |
# abc, def and ghi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment