joining string to next string in list
<p>I have a list with a large number of words in it:
sentence = ['a','list','with','a','lot','of','strings','in','it']</p>

<p>I want to be be able to go through the list and combine pairs of words according to some conditions I have. e.g.</p>

<p>['a','list','with','a','lot','of','strings','in','it'] 
becomes
['a list','with','a lot','of','strings','in','it']</p>

<p>I have tried something like:</p>

<pre><code>for w in range(len(sentence)):
    if sentence[w] == 'a':
        sentence[w:w+2]=[' '.join(sentence[w:w+2])]
</code></pre>

<p>but it doesn't work because joining the strings, decreases the size of the list and causes an index out of range. Is there a way to do this with iterators and .next() or something?</p>
