How do I test if an object is a sequence?
Cousin Stanley
CousinStanley at hotmail.com
Mon Dec 22 10:06:52 EST 2003
| Is there a common idiom for testing if an object is a sequence?
| ....
Max M ....
What about checking against a pre-defined dictionary
of types ???
>>>
>>> def isseq( obj ) :
... seq_types = { list : 1 , tuple : 1 , dict : 1 }
... if seq_types.has_key( type( obj ) ) :
... return True
... else :
... return False
...
>>>
>>> l = []
>>> t = ()
>>> d = {}
>>> n = 42
>>> s = "Yo Ho Ho and a bottle o' Rum"
>>>
>>> isseq( l )
True
>>>
>>> isseq( t )
True
>>>
>>> isseq( d )
True
>>>
>>> isseq( n )
False
>>>
>>> isseq( s )
False
--
Cousin Stanley
Human Being
Phoenix, Arizona
More information about the Python-list
mailing list