DEV Community

Discussion on: Adding values to an empty list

Collapse
 
itchyonion profile image
Jon Obi

Thanks to @dmitrypolo and @Fredrik Bengtsson for their help. It does what i want now! hurray!! lol.

myUniqueList = []

def addToMyUniqueList(x):
if x not in myUniqueList:
print("New item added:", x)
return myUniqueList.append(x)
else:
print("ERROR!!! Item already exists!")

addToMyUniqueList("salt")
print(myUniqueList)