Created
July 12, 2020 16:52
-
-
Save jeongm-in/c6ef45f23b82e4e8239424c7b4c118d2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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