Deja Vu code coach problem | Sololearn: Learn to code for FREE!

+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!

11/3/2020 11:17:07 AM

Atulya

10 Answers

New Answer

0

Got my logic πŸ‘πŸ‘thank you

+8

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.

+5

David Carroll I am going to look that up and try that out. Thanks for sharing that!

+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')

+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. πŸ˜‰

+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')

+1

Uh can use dictionaries also

+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))

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' )

0

With the any() function: l = input() if any([l.count(i) > 1 for i in l]): print("Deja Vu") else: print("Unique")