aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Steele Farnsworth <[email protected]>2020-07-09 11:20:01 -0400
committerGravatar GitHub <[email protected]>2020-07-09 11:20:01 -0400
commit8cba21c353a728d2c09ad82a425c46ce3f03abf0 (patch)
treeabfd52a014d0067b8d2e4078ab148419b3b31713
parentRemoved hard line breaks (diff)
Update range-len.md
Removed all blank lines to improve how it's rendered on Discord; thanks @kwzrd for rendering this!
-rw-r--r--bot/resources/tags/range-len.md4
1 files changed, 0 insertions, 4 deletions
diff --git a/bot/resources/tags/range-len.md b/bot/resources/tags/range-len.md
index 9b88aab47..65665eccf 100644
--- a/bot/resources/tags/range-len.md
+++ b/bot/resources/tags/range-len.md
@@ -1,15 +1,11 @@
Iterating over `range(len(...))` is a common approach to accessing each item in an ordered collection.
-
```py
for i in range(len(my_list)):
do_something(my_list[i])
```
-
The pythonic syntax is much simpler, and is guaranteed to produce elements in the same order:
-
```py
for item in my_list:
do_something(item)
```
-
Python has other solutions for cases when the index itself might be needed. To get the element at the same index from two or more lists, use [zip](https://docs.python.org/3/library/functions.html#zip). To get both the index and the element at that index, use [enumerate](https://docs.python.org/3/library/functions.html#enumerate).