+ 1

Is There Another Easy Solution?#2

If you are given a string of random letters, your task is to evaluate whether any letter is repeated in the string or if you only hit unique keys while you typing. Input Format: A string of random letter characters (no numbers or other buttons were pressed). Output Format: A string that says 'Deja Vu' if any letter is repeated in the input string, or a string that says 'Unique' if there are no repeats.

19th Dec 2024, 2:28 PM
HASAN IMTIAZ
HASAN IMTIAZ - avatar
3 Antworten
+ 5
HASAN IMTIAZ , you are on the right way by using a set. > a set can *not* have duplicated characters. so if duplicated characters occur, they will be removed automatically during the creation of the set. > what about using the *complete string* and make it a set. > than compare the length (number of characters) from the set with the length of the input string. > if length equals, there has been no duplicated characters in the input string. > if the length differs, the input string contains duplicated characters.
19th Dec 2024, 7:50 PM
Lothar
Lothar - avatar
+ 1
text = input() repeat = set() condition = False for char in text: if char in repeat: condition = True repeat.add(char) if condition: print("Deja Vu") else: print("Unique")
19th Dec 2024, 2:28 PM
HASAN IMTIAZ
HASAN IMTIAZ - avatar
+ 1
Did your answer work? Also, if the condition is true, why continue to search the rest and not break the for loop?
19th Dec 2024, 7:08 PM
Ausgrindtube
Ausgrindtube - avatar