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