fork download
  1. myUniqueList = []
  2. myLeftovers = []
  3.  
  4. def addList(newThing):
  5. if newThing in myUniqueList:
  6. myLeftovers.append(newThing)
  7. return False
  8. else:
  9. myUniqueList.append(newThing)
  10. return True
  11.  
  12. print(myUniqueList) # []
  13. print(addList("Meliodas")) # returns 'True' since it's a new item
  14. print(addList("Escanor")) # returns 'True' since it's a new item
  15. print(addList("Meliodas")) # returns 'False' since it's already been added
  16. print(myUniqueList) # This includes the new entries
  17. print(myLeftovers) # This includes any repeated entries
  18.  
Success #stdin #stdout 0.02s 9060KB
stdin
Standard input is empty
stdout
[]
True
True
False
['Meliodas', 'Escanor']
['Meliodas']