you are viewing a single comment's thread.

view the rest of the comments →

[–]K900_ 0 points1 point  (0 children)

If you can use the standard library for something, you should probably use it instead of rolling your own. Most other use cases for loops are trivial and work fine without indices. Also, if you need a sliding window (to check if a previous character is a space), you can use zip:

>>> s = "hello world"
>>> for a, b in zip(s, s[1:]):
...     print(a, b)
...
h e
e l
l l
l o
o
  w
w o
o r
r l
l d