Code Coach (Deja Vu) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Code Coach (Deja Vu)

I don't know what's wrong with my code. It's supposed to output "Deja Vu" or "Unique " once. But, it's repeating it the number of times the letter is repeated. What am I doing wrong? Code below: from collections import Counter string = input() def check(string): freq = Counter(string) for key in freq: if freq.get(key) > 1: print("Deja Vu") else: print ("Unique") check (string)

25th Feb 2020, 12:36 PM
Marvellous Abia
Marvellous Abia - avatar
1 Answer
+ 1
"for key in freq:" is effectively iterating over each letter in the input if im not mistaken. Importing counter is just confusing me. As you have it set up, as it goes through each iteration, it will print either "Deja Vu" or "Unique" this is not what you want. I would personally start with an empty list, iterate through each letter of the string, and if any of the letters that are in the list try to be added again, it would print "deja vu", else, it would print "unique"
12th Apr 2020, 4:50 PM
Slick
Slick - avatar