How can I alter the index of loop for a list
<p>I've a list and I want to display the content with index by manually changing the value of index. I've tried to do it in two ways but it is not working.</p>

<p>way 1:</p>

<pre><code>x=['hello','how','are','you','hope','you','are','fine','I','am','doing','work','in','python']
for i,item in enumerate(x):
  print (i,item)
  if item == 'are':
    i+=2
</code></pre>

<p>way 2:</p>

<pre><code>x=['hello','how','are','you','hope','you','are','fine','I','am','doing','work','in','python']
for i in xrange(len(x)):
  print x[i]
  if item == 'are':
    i+=2
</code></pre>

<p>The issue here is that both <code>enumerate()</code> and <code>xrange()</code> generate a series of values that is unaffected by external changes to <code>i</code>, which is an unconnected variable. Using @efferalgans's suggestion the best way might be to call the <code>next()</code> function twice, but this will mean storing a reference to the generator. So you want to do something like this:</p>

<pre><code>x=['hello','how','are','you','hope','you','are','fine','I','am','doing','work','in','python']
g = enumerate(x)
for i,item in g:
  print (i,item)
  if item == 'are':
    next(g)
    next(g)
</code></pre>

<p>from which I see the result</p>

<pre><code>0 hello
1 how
2 are
5 you
6 are
9 am
10 doing
11 work
12 in
13 python
</code></pre>

python python-2.7 nltk