For loop not working without range() " string indices must be integers"
<p><code>i</code> is a string, so how can I make this work? </p>

<p>How can I use <code>i</code> as index?</p>

<pre><code>for i in s[1:]:
    if s[i] &lt;= s[i-1]:
        temp += s[i]
    else:
        subs.append(temp)
        temp = ''
</code></pre>

<p>I've tried to use </p>

<pre><code>for i in s[1:]:
    if s.index(i) &gt;= s.index(i-1):
        temp += s[i]
    else:
        subs.append(temp)
        temp = ''
</code></pre>

<p>And I get</p>

<blockquote>
  <p>TypeError: unsupported operand type(s) for -: 'str' and 'int'</p>
</blockquote>

<p>When you iterate through a string using "for i in s[1:]", it will assign i the value of each character in the string. You may want to use the iterator "enumerate" in the loop instead. It will assign a sequential numeric value to every byte in the string, while assigning s[i] to v.</p>

<pre><code>for i, v in enumerate(s):
    if v &lt;= s[i-1]:
        temp += v
    else:
        stubs.append(temp)
        temp = ''
</code></pre>

python for-loop