jeudi 3 septembre 2020

How to solve if only one list is allowing value to be appended to it? [duplicate]

I have a small program that is written to differentiate unique and common numbers and separate them between two list. I've used an if statement to sort through any values inputted into the function it's in, yet only one of the lists keeps it's passed values. Please see below.

#Lists

myUniqueList = []
myLeftovers = []

def AddUnique():

    ListItem = input("Please input a value >> ")

    if myUniqueList [:] == ListItem:
        myLeftovers.append(ListItem)
    else:
        myUniqueList.append(ListItem)

    return PrintLists()


def PrintLists():

    print("\nPlease choose which list to print out.\n")
    print("1. List of Unique values")
    print("2. List of Duplicate values\n")

    list = input(">> ")
    if list == "1":
        print("\n")
        print(myUniqueList)
        print("\n")
    elif list == "2":
        print("\n")
        print(myLeftovers)
        print("\n")
    else:   
        print("\nPlease choose option-1 or option-2")
        PrintLists()
    return AddUnique()

AddUnique()

When the program is ran no matter how many common values I add, they all go to the same list regardless of what was defined within the if statement. Is there something I'm overlooking?

Aucun commentaire:

Enregistrer un commentaire