Also in Python we generally prefer to iterate over objects in a list (or tuple, or other so-called "iterable") rather than using an index of range(len(thing)).
So for example, instead of:
n = len(activities)
for i in range(n):
print(activities[i])
This is more direct and readable:
for activity in activities:
print(activity)
If we do need an index as well, enumerate is often used:
for i, activity in enumerate(activities):
print(i, activity)
Also in Python we generally prefer to iterate over objects in a list (or tuple, or other so-called "iterable") rather than using an index of
range(len(thing))
.So for example, instead of:
This is more direct and readable:
If we do need an index as well,
enumerate
is often used: