[Chicago] FW: Playing with generics

Michael Tobis mtobis at gmail.com
Thu Nov 17 21:22:07 CET 2005


If I understand what you are after correctly, I would prefer
functional programming for this sort of thing.

How about:


####

from operator import add

def toSequence(item):
   try: iter(item)
   except: return [item]
   else: return item

def Flatten(listOfListsAndScalars):

   # nonrecursive: handles only one level of list nesting
   # see also http://aspn.activestate.com/ASPN/Mail/Message/python-tutor/2302137

   return reduce(add,[toSequence(item) for item in listOfListsAndScalars])

##########
from math import atan, pi
scale = 180./pi

def RobertCalc(*args):
    xa,ya = Flatten(args)[:2]
    return atan(xa/ya)*scale

##########
# -mt


More information about the Chicago mailing list