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
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
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/
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