lundi 16 juillet 2018

Python if statement not recognized though conditions appear to be met

I'm trying to add 1 to the count each time there's a new letter and keep track of the doubled letters, but python isn't going into the if statement, despite line 6 showing the conditions for the if statement are met. What am I missing?

def duplicate_count(text):
    count = 0
    doubled_letters = []
    for i in text:
        print (i)
        print(i in doubled_letters)
        if i in doubled_letters == False:
            count += 1
            doubled_letters.append(i)
    print(count)
    print(doubled_letters)
    return count

duplicate_count("abbcdea")

this returns:

a
False
b
False
b
False
c
False
d
False
e
False
a
False
0
[]

Aucun commentaire:

Enregistrer un commentaire