+ 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!
15 Answers
0
Got my logic 👍👍thank you
+ 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.
+ 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))
+ 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')
+ 1
I think sets should be used... Set cannot have the same element
+ 1
Also smallest:
text=input()
print("Deja Vu" if len(text)!=len(set(text)) else "Unique")
+ 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
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")
0
#it also worked
text=input()
n=[text.count(i) for i in text]
if max(n)>=2:
print ("Deja Vu")
else:
print ("Unique")