diff options
author | 2023-11-18 15:00:24 -0500 | |
---|---|---|
committer | 2023-11-18 15:00:24 -0500 | |
commit | 96038fd9c1f6af1df62dbe875847930e0472a87a (patch) | |
tree | 5430e94d4acab091ee0fe0c84c75acf21a39168a | |
parent | Capitalize "Discord" in header; Change print statement to 'Code goes here on ... (diff) |
Rewriting of non-code sections.
The previous version began with "Iterating over range-len is a common approach ...", which sounds like an endorsement. Also removed "is guaranteed to produce elements in the same order", as I don't think anyone is actually confused about that. (I wrote the previous version--this is a criticism of my own writing.)
-rw-r--r-- | bot/resources/tags/range-len.md | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/bot/resources/tags/range-len.md b/bot/resources/tags/range-len.md index 4bd377d59..76fe9051e 100644 --- a/bot/resources/tags/range-len.md +++ b/bot/resources/tags/range-len.md @@ -2,12 +2,12 @@ embed: title: "Pythonic way of iterating over ordered collections" --- -Iterating over `range(len(...))` is a common approach to accessing each item in an ordered collection. +Beginners often iterate over `range(len(...))` because they look like Java or C-style loops, but this is almost always a bad practice in Python. ```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: +It's much simpler to iterate over the list (or other sequence) directly: ```py for item in my_list: do_something(item) |