jeudi 17 juin 2021

Using counter as condition in Python

I'm trying to do a condition based the number of apparitions of the variables. If any variable appears more than once it will appear as wrong if each variable appears once it will only appear as right. I tried this but didn´t work:

from collections import Counter
z = ['blue', 'red', 'yellow']
Counter(z)
print(Counter(z))

if Counter(z).items() != 1:
    print('Wrong')
else:
    print('Right')

Aucun commentaire:

Enregistrer un commentaire