diff options
Diffstat (limited to '')
| -rw-r--r-- | bot/resources/tags/str-join.md | 6 | 
1 files changed, 3 insertions, 3 deletions
| diff --git a/bot/resources/tags/str-join.md b/bot/resources/tags/str-join.md index e8407ac26..6390db9e5 100644 --- a/bot/resources/tags/str-join.md +++ b/bot/resources/tags/str-join.md @@ -9,15 +9,15 @@ for color in colors:      output += color + separator  print(output) # Prints 'red, green, blue, yellow, '  ``` -However, this solution is flawed. The separator is still added to the last color, and it is slow. +However, this solution is flawed. The separator is still added to the last element, and it is slow. -The better way is to use `str.join`. +The better solution is to use `str.join`.  ```py  colors = ['red', 'green', 'blue', 'yellow']  separator = ", "  print(separator.join(colors)) # Prints 'red, green, blue, yellow'  ``` -This method is much simpler, faster, and solves the problem of the extra separator. An important thing to note is that you can only `str.join` strings. For a list of ints,  +This solution is much simpler, faster, and solves the problem of the extra separator. An important thing to note is that you can only `str.join` strings. For a list of ints,  you must convert each element to a string before joining.  ```py  integers = [1, 3, 6, 10, 15] | 
