Making It Safer : Yield : Statement PYTHON TUTORIALS


PYTHON TUTORIALS » Statement » Yield »

 

Making It Safer


def flatten(nested):
    try:
        try: nested + ''
        except TypeError: pass
        else: raise TypeError
        for sublist in nested:
            for element in flatten(sublist):
                yield element
    except TypeError:
        yield nested
print list(flatten(['foo', ['bar', ['baz']]]))



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON TUTORIALS

 Navioo Statement
» Yield