Trinary operator?
Jeff Shannon
jeff at ccvcorp.com
Fri Apr 19 18:10:24 EDT 2002
In article <mailman.1019250162.24332.python-list at python.org>,
pyth at devel.trillke.net says...
> On Fri, Apr 19, 2002 at 10:47:09PM +0200, Philipp Lenssen wrote:
>
> > (huge code fragments deleted :-)
>
> really? wouldn't these few simple lines do what you/one want/s?
>
> genderdict = { 'english': { 'm':'male', 'f':'female'},
> 'german' : { 'm':'männlich','f': 'weiblich'} }
>
> return genderdict.get(language,{}).get(gender,'UNKNOWN')
>
Or, alternately:
genderdict = { ('english', 'm') : 'male',
('english', 'f') : 'female',
('german', 'm') : 'männlich',
('german', 'f') : 'weiblich' }
return genderdict.get( (language, gender), 'UNKNOWN' )
using a dictionary keyed on tuples, instead of nested
dictionaries. I'm not sure which would be preferable -- I expect
that it would depend on the typical usages.
--
Jeff Shannon
Technician/Programmer
Credit International
More information about the Python-list
mailing list