Skip to content

Instantly share code, notes, and snippets.

@jeongm-in
Created July 12, 2020 16:52
Show Gist options
  • Save jeongm-in/c6ef45f23b82e4e8239424c7b4c118d2 to your computer and use it in GitHub Desktop.
Save jeongm-in/c6ef45f23b82e4e8239424c7b4c118d2 to your computer and use it in GitHub Desktop.
def print_list(list):
# check for empty list
if not list:
print("")
return
print(list[0], end="")
if len(list) > 1:
for index, item in enumerate(list[1:-1]):
print(f", {item}", end="")
if len(list) == 2:
print(f" and {list[-1]}", end="")
else:
print(f", and {list[-1]}", end="")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment