Skip to content

Commit 02a238b

Browse files
authored
Use append instead of re-assigning full list
In order to reinforce the introduction of append in the earlier lists episode, it might be smart to use it here and take advantage of the mutability of lists, rather than just re-creating the whole list. The `print(odds)` line is optional and could be removed. It was added to reinforce visually the contents of the list after the append functions.
1 parent 073418e commit 02a238b

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

episodes/for-loops.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,15 @@ We can call the loop variable anything we like, there must be a colon at the end
9191
Loops are more robust ways to deal with containers like lists. Even if the values of the `odds` list changes, the loop will still work.
9292

9393
```python
94-
odds = [1, 3, 5, 7, 9, 11]
94+
odds.append(9)
95+
odds.append(11)
96+
print(odds)
9597
for num in odds:
9698
print(num)
9799
```
98100

99101
```output
102+
[1, 3, 5, 7, 9, 11]
100103
1
101104
3
102105
5

0 commit comments

Comments
 (0)