Le Friday 05 September 2008 00:47:00 Chris Rebert, vous avez écrit :
"premature optimization is the root of all evil"
I don't recall the OP wanted a (a bit) faster solution to his problem in
counterpart of memory loss and syntax complication.
If the OP's proposal seems already messy, how about ths one :
if lib.lower() not in ( e[0] for e in stage_map.items () ) :
...
--
_____________
Maric Michaud
On Thu, Sep 4, 2008 at 3:37 PM, Robert Dailey <rcdailey@gmail .comwrote:
>
Then store the string in its original case in the value part of the
key-value pair:
>
stage_map[key.lower()] = (key,whatever)
>
On Thu, Sep 4, 2008 at 5:21 PM, Fredrik Lundh <fredrik@python ware.com>
wrote:
So you're saying to ensure that stage_map's keys are initially lower-case
to begin with? Well, I can't do this either since the case of the keys is
actually valuable later on. It's only for the purposes of this specific
comparison operation that the case should be ignored.
wrote:
Robert Dailey wrote:
>I currently have a dictionary object that I'm doing the following with:
>>
>if lib not in stage_map:
> # ... do stuff ...
>>
>However, this will perform a case-sensitive comparison between lib and
>each key in stage_map. Is there a way to make this do a
>case-insensitive comparison instead?
>
dictionary lookups use the exact value. to make a case-insensitive
lookup, use key.lower() instead of key when creating the dictionary, and
then do
>
if lib.lower() not in state_map:
...
>I currently have a dictionary object that I'm doing the following with:
>>
>if lib not in stage_map:
> # ... do stuff ...
>>
>However, this will perform a case-sensitive comparison between lib and
>each key in stage_map. Is there a way to make this do a
>case-insensitive comparison instead?
>
dictionary lookups use the exact value. to make a case-insensitive
lookup, use key.lower() instead of key when creating the dictionary, and
then do
>
if lib.lower() not in state_map:
...
to begin with? Well, I can't do this either since the case of the keys is
actually valuable later on. It's only for the purposes of this specific
comparison operation that the case should be ignored.
Then store the string in its original case in the value part of the
key-value pair:
>
stage_map[key.lower()] = (key,whatever)
>
I don't recall the OP wanted a (a bit) faster solution to his problem in
counterpart of memory loss and syntax complication.
If the OP's proposal seems already messy, how about ths one :
if lib.lower() not in ( e[0] for e in stage_map.items () ) :
...
- Chris
>
>
--
_____________
Maric Michaud