News for hackers. Stuff that matters.
Re:The Python IAQ: Infrequently Answered Questions by Kilimanjaro on Friday November 12, 2010 @09:16AM (#1897681)
Sometimes I put short ifs in one line, just personal taste

    def fact(n):
        if n<=1: return 1
        else:    return n * fact(n-1)
Re:The Python IAQ: Infrequently Answered Questions by kolektiv on Friday November 12, 2010 @11:01AM (#1898047)
One of those times when I hugely miss languages with pattern matching/guards.

  fact(1) = 1
  fact(n) = n * fact(n-1)
Seems much more readable to me.
Re:The Python IAQ: Infrequently Answered Questions by Kilimanjaro on Friday November 12, 2010 @09:19AM (#1897695)
Which I guess can be written like

   def fact(n):
        return 1 if n<=1 else n*fact(n-1)
Re:The Python IAQ: Infrequently Answered Questions by danio on Friday November 12, 2010 @09:28AM (#1897727)
unfortunately not on python 2.4, which is the version we have on our production servers (2 yr old Linux)
Re:The Python IAQ: Infrequently Answered Questions by Kilimanjaro on Friday November 12, 2010 @04:55PM (#1899443)
One liner

    def fact(n): return n*fact(n-1) if n>1 else 1