x = [] try: x.index(4) except ValueError: pass else: x.append(4) #4 should be appended to x if 4 is not already in x