what is the the best way to express following:

James Stroud jstroud at ucla.edu
Tue Mar 28 04:43:33 CEST 2006


AndyL wrote:
> if type(key).__name__ == "int" or type(key).__name__ == "long":
>     abc()
> elif type(key).__name__ == "str":
>     efg()
> elif type(key).__name__ == "tuple" or type(key).__name__ == "list":
>     ijk()
> 
> 
> In other words I need to determinie intiger type or string or []/() in 
> elegant way, possibly without or ...
> 
> Thx, A.

Here is a suggestion

todo = {(int, long):abc, (str,):afg, (tuple, list):ijk}
todo[type(key)]()


James

-- 
James Stroud
UCLA-DOE Institute for Genomics and Proteomics
Box 951570
Los Angeles, CA 90095

http://www.jamesstroud.com/



More information about the Python-list mailing list