Elegantly handle different parameter types
<p>I have a function that, in the simplest of cases, operates on an iterable of items.</p>

<pre><code>def foo(items):
    for item in items:
        # do stuff
</code></pre>

<p>Sometimes, I do not want to pass it an iterable of items directly, but rather an object that provides a method to get the iterable:</p>

<pre><code>def foo(obj):
    for item in obj.iteritems():
        # do same stuff as above
</code></pre>

<p>I can merge these two cases like this:</p>

<pre><code>def foo(obj):
    try:
        items = obj.iteritems()
    except ValueError:
        items = obj
    for item in items:
        # do stuff
</code></pre>

<p>This works just fine. Now I get a third use case that looks like this:</p>

<pre><code>def foo(objs):
    for item in itertools.chain.from_iterable(obj.iteritems() for obj in objs):
        # do same stuff again
</code></pre>

<p>I can still use the <code>try-except</code> approach, since the interfaces are incompatible. However, the nested try catch would start to become very ugly. More so when I want to add a fourth use-case. Is there any way to solve this without nesting the <code>try</code>-blocks?</p>
