-
-
Save DugalMcCrow/ef3f4781630409b3f49b3e7b0c9789a6 to your computer and use it in GitHub Desktop.
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
>>> # Create a list of students based on their arrival sequence | |
>>> students = ['John', 'Aaron', 'Jennifer', 'Ashley'] | |
>>> | |
>>> # Lengthy way | |
>>> for index in range(len(students)): | |
... student = students[index] | |
... print(f"Arrival # {index+1}: {student}") | |
... | |
Arrival # 1: John | |
Arrival # 2: Aaron | |
Arrival # 3: Jennifer | |
Arrival # 4: Ashley | |
>>> | |
>>> # Concise way | |
>>> for index, student in enumerate(students, 1): | |
... print(f"Arrival # {index}: {student}") | |
... | |
Arrival # 1: John | |
Arrival # 2: Aaron | |
Arrival # 3: Jennifer | |
Arrival # 4: Ashley |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment