How do I test if an object is a sequence?

Lonnie Princehouse fnord at
Mon Dec 22 22:25:55 CET 2003

> Is there a common idiom for testing if an object is a sequence?

Try iterators...

def is_sequence(thing):
    return True   
  except TypeError:
    return False

Of course, this will return True for strings, but I suspect most 
people would say that strings are sequences.  You will have
to special-case them.

More information about the Python-list mailing list