nghoffma wrote:
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]))


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 :-)

You can also filter out Nones with a list/generator comprehension, but sets are just more elegant...

--
Ciao,
Matteo
--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to