Skip to content

Instantly share code, notes, and snippets.

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 DugalMcCrow/ef3f4781630409b3f49b3e7b0c9789a6 to your computer and use it in GitHub Desktop.
Save DugalMcCrow/ef3f4781630409b3f49b3e7b0c9789a6 to your computer and use it in GitHub Desktop.
>>> # 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