Loop character A/B alternately
<p>How can I print A/B character alternately in python loop?</p>

<p>What I expect in result:</p>

<pre><code>oneA
twoB
threeA
fourB
...
</code></pre>

<p>At the suggestion of @Graipher instead of using combined <code>zip()</code> with <code>itertools.cycle()</code>, better and simpler solution will be use <code>itertools.product()</code> which is </p>

<blockquote>
  <p>Cartesian product of input iterables.</p>
  
  <p>Roughly equivalent to nested for-loops in a generator expression. For example, product(A, B) returns the same as ((x,y) for x in A for y in B).</p>
</blockquote>

<p><a href="https://docs.python.org/2/library/itertools.html#itertools.product" rel="nofollow">https://docs.python.org/2/library/itertools.html#itertools.product</a></p>

<pre><code>words = ['one', 'two', 'three'] 
for word, i in itertools.product(words, ('A', 'B')):
    print(word+i)
</code></pre>

python loops for-loop