The syntax for checking if an item is already in a list and then adding it to a list if it is not is:
foo = []
if item not in foo:
foo.append(item)
# do something
This can execute code on the condition that the item is not in foo. This syntax seems to duplicate the logic of a set datatype in python, yet the following syntax does not exist;
bar = set()
if not bar.add(item):
# do something
but add() returns nothing, so this is not possible. So how does one execute some logic conditionally on an item being in a set?
Note: the reason a set is desired is the operation of adding a unique value to a set is of O(1), whereas the same operation is O(n) on a list.