Righard van Roy <pluij...@gmail.com> writes:
> I want to add an item to a list, except if the evaluation of that item
> results in an exception.

This may be overkill and probably slow, but perhaps most in the spirit
that you're asking.

    from itertools import chain

    def r(x):
        if x > 3:
            raise(ValueError)
        return x

    def maybe(func):
      try:
         yield func()
      except:
         return

    def p(i): return maybe(lambda: r(i))

    your_list = list(chain(p(1), p(5)))
    print your_list
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to