14 AnswersNew Answer
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!
11/3/2020 11:17:07 AMAtulya
14 AnswersNew Answer
Got my logic 👍👍thank you
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.
David Carroll I am going to look that up and try that out. Thanks for sharing that!
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')
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. 😉
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')
Uh can use dictionaries also
def checker(text): r = '' for i in text: if r != i: r = i else: return 'Deja Vu' return 'Unique' t = input() print(checker(t))
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')
I think sets should be used... Set cannot have the same element
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' )
With the any() function: l = input() if any([l.count(i) > 1 for i in l]): print("Deja Vu") else: print("Unique")
#it also worked text=input() n=[text.count(i) for i in text] if max(n)>=2: print ("Deja Vu") else: print ("Unique")
Also smallest: text=input() print("Deja Vu" if len(text)!=len(set(text)) else "Unique")
Sololearn Inc.535 Mission Street, Suite 1591
Send us a message