Skip to content

Instantly share code, notes, and snippets.

@euccas
Last active June 8, 2020 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save euccas/dcc7a67d6bbda30e608231a51f3794bd to your computer and use it in GitHub Desktop.
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".
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