Em Seg, 2006-03-27 às 18:43 -0800, James Stroud escreveu:
> Here is a suggestion
>
> todo = {(int, long):abc, (str,):afg, (tuple, list):ijk}
> todo[type(key)]()
Maybe...
todo = {(int, long): abc, basestr: afg, (tuple, list): ijk}
(y for x,y in todo.iteritems() if isinstance(key, x)).next()()
Fo
AndyL wrote:
> James Stroud wrote:
>
>> Here is a suggestion
>>
>> todo = {(int, long):abc, (str,):afg, (tuple, list):ijk}
>> todo[type(key)]()
>
>
>
> Is not that a shortcut? I have got "KeyError" exception ...
No, I hit send too soon, mixing ideas in my head. Paul McGuire's answer
is the wa
Paul McGuire wrote:
> "AndyL" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
>
>>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":
>> i
James Stroud wrote:
> Here is a suggestion
>
> todo = {(int, long):abc, (str,):afg, (tuple, list):ijk}
> todo[type(key)]()
Is not that a shortcut? I have got "KeyError" exception ...
--
http://mail.python.org/mailman/listinfo/python-list
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
"AndyL" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> 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
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 with