In Java I like to use the Boolean value returned by an \"add to the set\" operation to test whether the element was already present in the set:
if (set.add(\
As mentioned in the previous answers, the add method for Python sets does not return anything. By the way, this exact question was discussed on the Python mailing list: http://mail.python.org/pipermail/python-ideas/2009-February/002877.html.