Last active
June 8, 2020 02:07
-
-
Save euccas/dcc7a67d6bbda30e608231a51f3794bd to your computer and use it in GitHub Desktop.
Generate a string connecting items of a given list. The string should look like:
a and b
a, b and c Being strict on the separator and "and".
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
item_names = mydict["items"].split() | |
if len(item_names) > 1: | |
item_names[-1] = "and " + dv_tiers[-1] | |
sep = ", " if len(item_names) > 2 else " " | |
namstr = sep.join(item_names) | |
print namestr # a, b and c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment