It would be nice to generalize the solution so it could also handle
definitions={"Deprecated": "No longer in use", "DEPRECATED":  "No longer in 
use"}
These are unique now, but after turning them into lower case not anymore. 
new_d = {}
for d in definitions:
    try:
        new_d[d.lower()].append(definitions[d])
    except TypeError:
        new_d[d.lower()] = [definitions[d]]
 

Cheers!!
Albert-Jan


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
All right, but apart from the sanitation, the medicine, education, wine, public 
order, irrigation, roads, a fresh water system, and public health, what have 
the Romans ever done for us?
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


>________________________________
>From: Joel Goldstick <joel.goldst...@gmail.com>
>To: tutor@python.org
>Sent: Thursday, October 27, 2011 8:36 PM
>Subject: Re: [Tutor] changing dictionary to lowercase
>
>
>
>
>
>On Thu, Oct 27, 2011 at 2:25 PM, ADRIAN KELLY <kellyadr...@hotmail.com> wrote:
>
>
>>Hi all,
>>is it possible to change a dictionary list to lowercase..without having to 
>>retype?
>>e.g. definitions={"Deprecated": "No longer in use", "Depreciation": "fall in 
>>value of an asset"}
>> 
>>i have tried definitions=definitions.lower()
>> 
>>regards
>>adrian
>>
>>
>>_______________________________________________
>>Tutor maillist  -  Tutor@python.org
>>To unsubscribe or change subscription options:
>>http://mail.python.org/mailman/listinfo/tutor
>>
>>There is a string method called lower so 'Bob'.lower() will return 'bob'
>
>You can't alter the keys in a dictionary because they are immutable -- they 
>can't be changed
>
>But you can loop through your dictionary, make new keys lowercase and copy the 
>values associated with each key
>
>like this:
>
>>>> new_d = {}
>
>>>> for d in definitions:
>...   new_d[d.lower()] = definitions[d]
>... 
>>>> new_d
>{'deprecated': 'No longer in use', 'depreciation': 'fall in value of an asset'}
>>>> 
>
>
>
>
>-- 
>Joel Goldstick
>
>
>_______________________________________________
>Tutor maillist  -  Tutor@python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor
>
>
>
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to