How do i put "if letter appears two times in a list,print deja vu" in python code 😅I'm a beginner | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 3

How do i put "if letter appears two times in a list,print deja vu" in python code 😅I'm a beginner

24th Apr 2022, 2:01 PM
M.e.r.c.y📍🖤
M.e.r.c.y📍🖤 - avatar
12 Answers
+ 2
Do not write in the input function An approach could be to create a set with the input and then compare the length of the set with the length of the original input string. The output must be written exactly as described in the task description
24th Apr 2022, 3:46 PM
Lisa
Lisa - avatar
+ 1
👉Please tag "Python" when you ask about Python, not "html". 👉Please elaborate what the task is (example input and output) 👉Show your attempt.
24th Apr 2022, 2:55 PM
Lisa
Lisa - avatar
+ 1
Is it a sololearn task? It asks for input() according to the task description?
24th Apr 2022, 3:10 PM
Lisa
Lisa - avatar
+ 1
You can use the count method of list and conditional statements. some_list = ['a', 'b', 'c', 'd', 'e', 'a'] letter = input() if some_list.count(letter) > 1: print("Deja Vu") else: print("Unique")
24th Apr 2022, 4:01 PM
Sandeep
Sandeep - avatar
0
Input Format: A string of random letter characters (no numbers or other buttons were pressed). Output Format: A string that says 'Deja Vu' if any letter is repeated in the input string, or a string that says 'Unique' if there are no repeats
24th Apr 2022, 3:02 PM
M.e.r.c.y📍🖤
M.e.r.c.y📍🖤 - avatar
0
letters="aa,bb,cc,df,ee,ff,g,hh,ii,jj,kk,ll,mm,nn,oo,pp,qq,rr,ss,tt,uu,vv,ww,xx,yy,zz" string="hello" if letters in string: print("Deja vu") elif letters not in string: print("Unique Here is my attempt above
24th Apr 2022, 3:04 PM
M.e.r.c.y📍🖤
M.e.r.c.y📍🖤 - avatar
0
Yes,it does,but i did it like that to see if it will work with my input string of which it doesn't
24th Apr 2022, 3:33 PM
M.e.r.c.y📍🖤
M.e.r.c.y📍🖤 - avatar
0
letters=['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z/n'] string=(input("string")) pos=0 long=len(letters) if letters[pos]in string*2: print("deja vu") else: print("unique") This here was my second attempt
24th Apr 2022, 3:34 PM
M.e.r.c.y📍🖤
M.e.r.c.y📍🖤 - avatar
0
Sandeep i tried this but,it works with some words but some,no
24th Apr 2022, 4:08 PM
M.e.r.c.y📍🖤
M.e.r.c.y📍🖤 - avatar
0
Lisa may you please elaborate more on your answer please
24th Apr 2022, 4:10 PM
M.e.r.c.y📍🖤
M.e.r.c.y📍🖤 - avatar
0
M.e.r.c.y📍🖤 it should work with everything. Maybe try adding an elif condition. ----- You can use the count method of list and conditional statements. some_list = ['a', 'b', 'c', 'd', 'e', 'a'] letter = input() if some_list.count(letter) > 1: print("Deja Vu") elif some_list.count(letter) == 1: print("Unique") else: print("") ----
24th Apr 2022, 4:13 PM
Sandeep
Sandeep - avatar
0
if string.count() == 2: # code here I dont know, this might help though.
25th Apr 2022, 5:13 PM
Thomas Walker