aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Galen Rice <[email protected]>2024-04-16 12:31:13 -0400
committerGravatar GitHub <[email protected]>2024-04-16 12:31:13 -0400
commit8e51e49d14aeb3131ff6bf989c32f86a4408f8c1 (patch)
tree12f579a6820bb8f46bcb8c19a2d9fef1e886725d
parentfix: condense some whitespace around code blocks (diff)
fix: further condense first code block
-rw-r--r--bot/resources/tags/loop-remove.md5
1 files changed, 1 insertions, 4 deletions
diff --git a/bot/resources/tags/loop-remove.md b/bot/resources/tags/loop-remove.md
index 8245c7d93..c46cb47ba 100644
--- a/bot/resources/tags/loop-remove.md
+++ b/bot/resources/tags/loop-remove.md
@@ -4,13 +4,10 @@ embed:
---
Avoid removing items from a collection, such as a list, as you iterate that collection in a `for` loop:
```py
-# Don't do this!
data = [1, 2, 3, 4]
for item in data:
data.remove(item)
-
-print(data)
-# [2, 4] # <- every OTHER item was removed!
+print(data) # [2, 4] <-- every OTHER item was removed!
```
`for` loops track the index of the current item with a kind of pointer. Removing an element causes all other elements to shift, but the pointer is not changed:
```py