Want more features on Pastebin? Sign Up, it's FREE!
Guest

compact if/else for python

By: a guest on Aug 23rd, 2010  |  syntax: Python  |  size: 0.48 KB  |  views: 143  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
This paste has a previous version, view the difference. Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. def ifel(expression):
  2.     def ifcase(ifstatement):
  3.         if expression:
  4.             def ifevaluator(elsestatement):
  5.                 return ifstatement
  6.             return ifevaluator
  7.         else:
  8.             def elseevaluator(elsestatement):
  9.                 return elsestatement
  10.             return elseevaluator
  11.     return ifcase
  12.  
  13. print ">>> ifel(35*20 > 10)(100)(20)"
  14. print ifel(35*20 > 10)(100)(20)
  15. print ">>> ifel(35*20 < 10)(100)(20)"
  16. print ifel(35*20 < 10)(100)(20)
clone this paste RAW Paste Data