Python paradigms

Aahz Maruch aahz at netcom.com
Sat Apr 15 23:55:15 EDT 2000


In article <8cmr70$b0e$1 at pegasus.csx.cam.ac.uk>,
Nick Maclaren <nmm1 at cus.cam.ac.uk> wrote:
>
>    x = (a != NULL ? a[i]->weeble : 0) + (b != NULL ? b[i]->wombat : 0)

Here's a solution I haven't seen before (refactored slightly for the
most likely equivalent Python idiom):

def expression_if( test, true, false ):
  if test: return true
  else: return false

x = expression_if( a is not None, 
   a[i].weeble, 0) + expression_if( b is not None, b[i].wombat, 0)
--
                      --- Aahz (Copyright 2000 by aahz at netcom.com)

Androgynous poly kinky vanilla queer het    <*>     http://www.rahul.net/aahz/
Hugs and backrubs -- I break Rule 6

"First one back from the bathroom gets to be the bottom."



More information about the Python-list mailing list