Cameron Laird wrote:
> In article <[EMAIL PROTECTED]>,
> Jan Schilleman <[EMAIL PROTECTED]> wrote:
>> Hi,
>>
>> try this:
>> func = getattr(operations, ["Replace", "ChangeCase", "Move"][n])
>>
>> HTH,
>> Jan
>>
>> "ianaré" <[EMAIL PROTECTED]> schreef in bericht 
>> news:[EMAIL PROTECTED]
>>> yeah the subject doesn't really make sense does it?
>>>
>>> anyway want I want to do is this:
>>> if n == 1:
>>>
>>>    self.operations.insert(pos, operations.Replace.Panel(self, main))
>                       .
>                       .
>                       .
> I think you meant "...[n - 1]" rather than "...[n]".
> 
> I'm a tiny bit surprised no one has organized this in terms
> of a dictionary.  I don't know, of course, how robust is the
> characterization of n as a small integer.  Maybe
> 
>   lookup_table = {
>       0: "Replace",
>       1: "ChangeCase",
>       2: "Move"}
> 
> captures the sentiment; maybe something else does it better.
> 
Surely for this requirement the *only* advantage of a dictionary over a 
list is its ability to index with arbitrary values and thereby avoid the 
need to use [n-1]. Wouldn't it therefore be less perverse to use

     lookup_table = {
       1: "Replace",
       2: "ChangeCase",
       3: "Move"}

Of course the dictionary would be a big win if the integer choice values 
weren't a linear sequence. Otherwise using a list with a fixed offset is 
likely to be quicker.

regards
  Steve
-- 
Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd          http://www.holdenweb.com
Skype: holdenweb     http://del.icio.us/steve.holden
Recent Ramblings       http://holdenweb.blogspot.com

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to