+ 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
14 Answers
+ 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.
+ 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.
+ 3
HonFu you mean by using for else
I literally forget that thing😂
+ 3
If it was about onelining it, I would take this:
print(['deja vu', 'unique'][(lambda s: len(s)==len(set(s)))(input())])
+ 3
It means part of a string.
When you use slicing in Python on str, you get a new string.
'thorn'[1:] -> 'horn'
+ 2
HonFu
Thanks sir I got it
I need to use for else here
+ 2
HonFu one lining that's so complex
If you have a moment
Could you explain it in parts for me
+ 2
HonFu I am just asking to define substring
+ 1
Flash
Thanks bro it's looking cool
+ 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
+ 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!!✍✍
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')
0
HonFu apart from that
If you tell me about substring, how it is made and difference between string and the same
0
Yes Taran Grover I Modified My Comment And Mentioned The Way I Solved.