For review: PEP 308 - If-then-else expression
Evan
evan at 4-am.com
Sun Feb 9 11:07:12 EST 2003
Erik Max Francis wrote:
>>t = {if "spam" not in s: "customer", "eggs" in s: "vikings",
>>"waitress"}
>
> The use of curly braces screams "dictionary" when there is not a
> dictionary in sight, and the use of the comma looks like tuples are
> involved when they are not.
I could care less about the curly braces and commas. The central idea
is an n-ary choice, presented in logical order, surrounded by grouping
delimiters that the parser can easily recognize, with no new keyword.
Any of these would do:
t = (if "spam" not in s: "customer", "eggs" in s: "vikings", "waitress")
t = (if "spam" not in s: "customer"
elif "eggs" in s: "vikings"
else: "waitress")
t = if:("spam" not in s, "customer",
"eggs" in s, "vikings",
"waitress")
Cheers,
Evan @ 4-am
More information about the Python-list
mailing list