Re: Dictionaries inside out

2010-11-26 Thread Ben Finney
Ben Finney writes: > code_by_desc = dict( > (desc, code) for (code, desc) in codes_to_messages.items()) Bah, I fumbled an edit. Try this:: code_by_desc = dict( (desc, code) for (code, desc) in desc_by_code.items()) -- \“The reason we come up with new versions

Re: Dictionaries inside out

2010-11-26 Thread Ben Finney
(Replying to Greg, though his original message doesn't appear at Gmane.) > Greg Lindstrom writes: > > > I am working on a project where I'm using dictionaries to hold the > > translations to codes (i.e., {'1':'Cheddar','2':'Ice > > Hockey','IL':'Thermostat Broken'}).  The bulk of the application

Re: Dictionaries inside out

2010-11-26 Thread Terry Reedy
On 11/26/2010 1:13 PM, Greg Lindstrom wrote: I am working on a project where I'm using dictionaries to hold the translations to codes (i.e., {'1':'Cheddar','2':'Ice Hockey','IL':'Thermostat Broken'}). The bulk of the application requires me to translate codes to their meaning, but it would be ni

Re: Dictionaries inside out

2010-11-26 Thread Gaëtan Podevijn
Found in Dive in Python 3 : >>> a_dict = {'a': 1, 'b': 2, 'c': 3} >>> {value:key for key, value in a_dict.items()} {1: 'a', 2: 'b', 3: 'c'} 2010/11/26 Burton Samograd > Greg Lindstrom writes: > > > I am working on a project where I'm using dictionaries to hold the > > translations to codes (i

Re: Dictionaries inside out

2010-11-26 Thread Burton Samograd
Greg Lindstrom writes: > I am working on a project where I'm using dictionaries to hold the > translations to codes (i.e., {'1':'Cheddar','2':'Ice > Hockey','IL':'Thermostat Broken'}).  The bulk of the application > requires me to translate codes to their meaning, but it would be nice > to be abl

Dictionaries inside out

2010-11-26 Thread Greg Lindstrom
I am working on a project where I'm using dictionaries to hold the translations to codes (i.e., {'1':'Cheddar','2':'Ice Hockey','IL':'Thermostat Broken'}). The bulk of the application requires me to translate codes to their meaning, but it would be nice to be able to translate a meaning back to th