What's the missing part in my code below?
This is related to Deja Vu problem. I'm getting "Unique" even if a string is repeated. Please help input_sentence = input() for letter in input_sentence: if input_sentence.count(letter)>=2: print("Deja Vu") else: print("Unique") break
8/1/2020 6:31:28 AMpsprises
14 AnswersNew Answer
A different approach input_sentence = input() or "hello" status = "Unique" for letter in input_sentence: if input_sentence.count(letter)>=2: status = "Deja Vu" break print(status) # alternatively unique_letters = set(input_sentence) # make a `set` containing unique letters from original input print("Unique" if len(input_sentence) == len(unique_letters) else "DeJa Vu") # compare original input length with the `set` length. Difference in size means there were duplicate.
Here is an other approach: No loop is used, but just a conparison of original input string and a set of input string (1) take your input string and get the length of it (2) use the same input string and make it a set and get also the length of it (3) if both length values are identical, the input string does not contain duplicated characters (4) if both length values are different, the string contains duplicatet characters
Happy to know that my answer helped someone , thanks for your information 😄
if any(input_sentence.count(letter)>=2 for letter in input_sentence): print("Deja Vu") else: print("Unique")
this might work: input_sentence = input() for letter in input_sentence: if input_sentence.count(letter) >1 : i=0 break else: i=1 print ("unique" if i==1 else "deja vu") edit: to whoever downvoter , why did you downvote me?? i was just trying to help him
Pendem Shiva Prakash continue is not used as often as break but it is essential in a loop that needs it. Check out the correction and other approaches...😃 https://code.sololearn.com/cka7kr8GdfM7/?ref=app
Pendem Shiva Prakash You're welcome 👌 Julia's code doesn't need `break` statement bro. In fact, it doesn't need to be put inside a loop at all.
Ipang ohhh....yeah, thank you bro for informing me that😁
Tomiwa Joseph Woah! Thank you for giving more than just a correction 😃😊
Ipang Thank you for answering 😊
Proলয় मिश्ra I don't know who downvoted your comment, but thank you for answering, it works😊
Lothar thank you for answering 😊
Julia Shabanova Thank you for answering, but your code works only when there is a break statement 😄