Tim Chase wrote: > >>> def flatten(x): > ... q = [] > ... for v in x: > ... if hasattr(v, '__iter__'): > ... q.extend(flatten(v)) > ... else: > ... q.append(v) > ... return q > ... Let's do some nitpicking on "pythonic" style. A more pythonic way to do it would be: try: q.extend(v) except TypeError: q.append(v)