+ 2

Deja Vu code coach problem

text=input() for i in range(0,len(text)): s=text[i] count = 0 for j in range(0,len(text)): if s==text[i]: count=count+1 if count >1 : print("Deja Vu") break if i == (len(text)-1): print("Unique") I am struck in this problem plzz help!

3rd Nov 2020, 11:17 AM
Atulya
Atulya - avatar
15 odpowiedzi
0
Got my logic 👍👍thank you
4th Nov 2020, 5:04 AM
Atulya
Atulya - avatar
+ 11
I like your solution. I used this approach: First I load the input into a list next I used set to convert a copy of the list to a set. Since sets do not allow duplicates I simply compared the len of the set and list to determine if it was deja vu or not.
9th Nov 2020, 5:40 PM
Paul K Sadler
Paul K Sadler - avatar
+ 5
David Carroll I am going to look that up and try that out. Thanks for sharing that!
9th Nov 2020, 6:52 PM
Paul K Sadler
Paul K Sadler - avatar
+ 4
s = input() c = 0 for l in s: if s.count(l) > 1: c += s.count(l) c -= int(c/2) if c > 1: print('Deja Vu') else: print('Unique')
3rd Nov 2020, 8:30 PM
Václav Dostál
Václav Dostál - avatar
+ 4
Paul K Sadler Another option could be to use the any() function on a sorted list. This can compare the current with the previous positions which will return True as soon as the first match is found. 😉
9th Nov 2020, 6:49 PM
David Carroll
David Carroll - avatar
+ 2
s = input() c = 0 for l in s: if s.count(l) > 1: c = s.count(l) if c > 1: print('Deja Vu') else: print('Unique')
9th May 2021, 4:23 PM
Jobayer Ahmed
Jobayer Ahmed - avatar
+ 1
Uh can use dictionaries also
19th Jan 2021, 7:31 AM
Manas Vig
Manas Vig - avatar
+ 1
def checker(text): r = '' for i in text: if r != i: r = i else: return 'Deja Vu' return 'Unique' t = input() print(checker(t))
1st Feb 2021, 7:52 PM
Henris
+ 1
Whoa. I did it a little different y'all. I'm not even sure what to say other than it worked. rndm_char = input() x = set(rndm_char) re_strng = ''.join(x) print('Unique' if len(rndm_char) == len(re_strng) else 'Deja Vu')
13th Dec 2021, 8:08 PM
Stephen Norton
Stephen Norton - avatar
+ 1
I think sets should be used... Set cannot have the same element
21st Feb 2022, 10:44 AM
Obi-Okonkwo Chisom
Obi-Okonkwo Chisom - avatar
+ 1
Also smallest: text=input() print("Deja Vu" if len(text)!=len(set(text)) else "Unique")
8th Jun 2022, 4:17 PM
Suprio Paul
Suprio Paul - avatar
+ 1
#Whoa. I think my code is probably the longest one here. #This code uses list, boolean and append() function. h = sorted(input()) l = [] o = False for i in range(-1, len(h)-1): i+=1 i <= len(h) if h[i] == h[i-1]: l.append("Yes") else: l.append("No") if l[i] == "Yes": o = True for q in range(i+1): q+=1 if l[i] == "Yes" and l[i-q] == "No": o = True if o is True and len(h) > 1: print("Deja Vu") else: print("Unique") #If there's at least 1 string "Yes" in the list, it should print Deja Vu, otherwise it prints Unique
25th Nov 2022, 1:42 AM
Dragon RB
Dragon RB - avatar
0
letters=input() c=[] for i in letters: c.append(1) if letters.count(i)>1 else c.append(0) print('Deja Vu' if sum(c)>=1 else 'Unique' )
6th Apr 2021, 8:06 AM
Ackøh Bwoy
Ackøh Bwoy - avatar
0
With the any() function: l = input() if any([l.count(i) > 1 for i in l]): print("Deja Vu") else: print("Unique")
18th Oct 2021, 6:12 AM
Mateo González Bufi
Mateo González Bufi - avatar
0
#it also worked text=input() n=[text.count(i) for i in text] if max(n)>=2: print ("Deja Vu") else: print ("Unique")
8th Jun 2022, 4:09 PM
Suprio Paul
Suprio Paul - avatar