<p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p>

<pre><code>&gt;&gt;&gt; import itertools
&gt;&gt;&gt; c = itertools.count(1)
&gt;&gt;&gt; items = ['foo', 'bar']
&gt;&gt;&gt; merged = imerge(items, c)  # the mythical "imerge"
&gt;&gt;&gt; merged.next()
'foo'
&gt;&gt;&gt; merged.next()
1
&gt;&gt;&gt; merged.next()
'bar'
&gt;&gt;&gt; merged.next()
2
&gt;&gt;&gt; merged.next()
Traceback (most recent call last):
    ...
StopIteration
</code></pre>

<p>What is the simplest, most concise way to do this?</p>

I'd do something like this. This will be most time and space efficient, since you won't have the overhead of zipping objects together. This will also work if both
```
a
```
and
```
b
```
are infinite.
```
```
def imerge(a, b):
    i1 = iter(a)
    i2 = iter(b)
    while True:
        try:
            yield i1.next()
            yield i2.next()
        except StopIteration:
            return
```
```