jeudi 22 octobre 2015

How do I check for list element in a list?

I have created a function that appends a list element to another list. The function is then supposed to check if the list element(stored in a variable) is present in the list, to then execute another function which chooses a new list element. It chooses by randomly generating a integer based on the length of the list. But its not doing so. The code for the entire program is available at the link below, and the function I am struggling to create is printed below. Sorry if the explanation is very uninformative. In short words, I am trying to get the following program to eliminate duplicates. I've tried shuffle() and others but to no avail. Any ideas:

def randcheck():
    global dcheck4
    dcheck = opposite1[decider]
    dcheck2 = opposite2[decider]
    dcheck3 = opposite1[decider2]
    dcheck4 = opposite2[decider2]
    dchecklist.append(dcheck)
    dchecklist.append(dcheck2)
    dchecklist.append(dcheck3)
    dchecklist.append(dcheck4)
    print(dchecklist)

    while opposite1[decider] in dchecklist:
        deciders()
    while opposite2[decider] in dchecklist:
        deciders()
    while opposite1[decider2] in dchecklist:
        deciders()
    while opposite2[decider2] in dchecklist:
        deciders()

Link to the full program code:

How do I generate random integers that are not repeated or duplicated?




Aucun commentaire:

Enregistrer un commentaire