http://loop-bell.livejournal.com/ ([identity profile] loop-bell.livejournal.com) wrote in [personal profile] nemorathwald 2009-01-18 02:32 am (UTC)

Here's a neat trick I've recently learned in Python for conditional assignments:

This:

if hour == 1:
   pluralHour  = ""
else
   pluralHour = "s"


Is the same as this:
pluralHour = "s" if hour == 1 else ""


I think the second actually shows a little more clearly what is being done, especially in cases like this where the if clause is short. (When the if clause is really long, it tends to make the lines get unreadably long when you do it this way)

In lojban terms, think of it as a sort of SE variety of conditianals -- the x2 gets rotated out to the front and then x1 and x3 follow. Or I also think of it as "inside out" notation, because the part that's normally in the middle comes first.

Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting