Trinary operator?
Philip Swartzleonard
starx at pacbell.net
Wed Apr 17 14:49:55 EDT 2002
Andrew Dalke || Wed 17 Apr 2002 11:20:15a:
> Philipp Lenssen:
>>can I use something like
>> verboseGender = (gender == 'm') ? 'male' : 'female'
>>in Python?
>
> No. Search the archives for "ternary operator" for plenty of
> past discussion. Google lists 65 posts for comp.lang.python.
>
> Besides, for this specific case you should have some error checking,
> because there are genders other than 'male' and 'female' (eg,
> asexual bacteria and hermaphradite earthworms).
>
> verboseGenderTable = {
> "m": "male",
> "f": "female", < # Most large eukaryotes
"a": "asexual", # Bacteria, etc
"h": "hermaphrodite", # Earthworms, etc
"n": "neuter", # Robots, AIs
"r": "refuse-to-stateist",# The paranoid
"u": "unknown" # We lack information /
# last seen in dark ally /
# raised by wolves, dosen't know
> }
> verboseGender = verboseGenderTable[gender]
--
Philip Sw "Starweaver" [rasx] :: www.rubydragon.com
More information about the Python-list
mailing list