+ 2

Is there any better way??

For this challenge https://www.sololearn.com/coach/54?ref=app I have a code something like this https://code.sololearn.com/cg8IaHWpPosR/?ref=app I guess there must be a better and efficient way to do this Something like if the print('deja vu') block has executed then break and don't print (unique) I know I can't explain much better, But I need some new function to try Thanks in advance

10th Jun 2020, 1:10 PM
Taran Grover
Taran Grover - avatar
15 Réponses
+ 7
This would be a typical way to do it: source = input() for i in source: x = source.count(i) if int(x)>1: print('Deja Vu') break else: print('Unique') Additionally you could write: for i in set(source) Like this, you make sure that the occurrence of a letter, if it's in there more than once, is only counted once.
10th Jun 2020, 1:38 PM
HonFu
HonFu - avatar
+ 4
The lambda function returns true or false (1 or 0) depending on if (condition). So either string 0 or string 1 is chosen. About substring... I don't get the question.
10th Jun 2020, 2:34 PM
HonFu
HonFu - avatar
+ 3
HonFu you mean by using for else I literally forget that thing😂
10th Jun 2020, 2:09 PM
Taran Grover
Taran Grover - avatar
+ 3
If it was about onelining it, I would take this: print(['deja vu', 'unique'][(lambda s: len(s)==len(set(s)))(input())])
10th Jun 2020, 2:20 PM
HonFu
HonFu - avatar
+ 3
It means part of a string. When you use slicing in Python on str, you get a new string. 'thorn'[1:] -> 'horn'
10th Jun 2020, 3:07 PM
HonFu
HonFu - avatar
+ 2
HonFu Thanks sir I got it I need to use for else here
10th Jun 2020, 2:10 PM
Taran Grover
Taran Grover - avatar
+ 2
HonFu one lining that's so complex If you have a moment Could you explain it in parts for me
10th Jun 2020, 2:27 PM
Taran Grover
Taran Grover - avatar
+ 2
HonFu I am just asking to define substring
10th Jun 2020, 3:02 PM
Taran Grover
Taran Grover - avatar
+ 1
Flash Thanks bro it's looking cool
10th Jun 2020, 2:09 PM
Taran Grover
Taran Grover - avatar
+ 1
Hey Taran Grover I Just Wanna Say That For Each And Every Program We Have Multiple Ways To Solve It. Lets Take Example Of This “Deja vu” Problem. Everyone Gave Their Own Solutions.Same Way My Method To Solve This Problem Is Different So Must Have A Look To My Program 😊 https://code.sololearn.com/cFbhAXq3881o/?ref=app
12th Jun 2020, 12:32 PM
Rahul Saxena
Rahul Saxena - avatar
+ 1
Ryan Daniel Yeah, That's true, but I make sure that I observe as many as possible code, I learn from every code I see, new function, new ways, there's everything to learn!!✍✍
12th Jun 2020, 12:41 PM
Taran Grover
Taran Grover - avatar
0
another way: print('Deja vu' if all((lambda x: [True if x.count(i) > 1 else False for i in x])(input())) else 'Unique')
10th Jun 2020, 1:47 PM
Flash
0
HonFu apart from that If you tell me about substring, how it is made and difference between string and the same
10th Jun 2020, 2:30 PM
Taran Grover
Taran Grover - avatar
0
Yes Taran Grover I Modified My Comment And Mentioned The Way I Solved.
12th Jun 2020, 12:44 PM
Rahul Saxena
Rahul Saxena - avatar