Since a function that doesn't return is equivalent to one that returns None, you can write it as:
>>> def doit(lst): ... s = set(lst) - set([None]) ... if s: return max(s)
that looks to me as the most elegant so far, but this is just because it's mine :-)
Cool. I prefer to be explicit about returns (e.g. not counting on the automatic return None), and I'd rather not create the unnecessary None set, so I would probably write this like:
py> def f(lst): ... s = set(lst) ... s.discard(None) ... if s: ... return max(s) ... else: ... return None ...
But it's definitely a very elegant solution. Thanks!
Steve -- http://mail.python.org/mailman/listinfo/python-list