Re: returning True, False or None

2005-02-04 Thread nghoffma
Is it cheating to use a Set? py>>def doit(thelist): ... s = sets.Set(thelist) ... if s == sets.Set([None]): ... return None ... else: ... return max(s) ... py>>print doit([ True , None , None , False ] ) True py>>print doit([ None , False , False , None ] ) Fals

Re: returning True, False or None

2005-02-04 Thread nghoffma
sorry, that should have been: py>>import sets py>>def doit(thelist): ... s = sets.Set(thelist) ... if s == sets.Set([None]): ... return None ... else: ... return max(s - sets.Set([None])) -- http://mail.python.org/mailman/listinfo/python-list

Re: Sorting a list of objects by multiple attributes

2006-04-10 Thread nghoffma
If you are lambda-phobic (as I am) this should also work for an arbitrary set of attributes: attrs = 'attr1 attr2 attr3'.split() sortlist = [[getattr(o,a) for a in attrs] + [o] for o in objects] sorted_objects = [x[-1] for x in sorted(sortlist)] -Noah -- http://mail.python.org/mailman/listinfo/

Re: Sorting a list of objects by multiple attributes

2006-04-11 Thread nghoffma
I'm sure my avoidance of lambdas as due as much to laziness as adherence to principle. This is a good opportunity to learn about them. I suggested the above because it wasn't obvious to me how one would pass the arbitrary set of attributes to the lambda expression (and I envisioned them being spe