+ 1

Which string functions do I use in the "Search Engine" project of python?

11th Feb 2021, 2:28 PM
Sarvam Fating
Sarvam Fating - avatar
12 Answers
+ 1
It is totally fine. You're code is correct, just get the input given by the challenge Because in challenges, we have to get the input to meet the expected output. In this challenge, it gives 2 of inputs (2 lines) which are the text and the word to find. First, let us get the input and assign the input value to variable. text = input() word = input() Additional, we don't need to print again while calling the function as the output is already printed inside. https://code.sololearn.com/cDY4avL3b0zG/?ref=app
12th Feb 2021, 5:28 AM
noteve
noteve - avatar
+ 4
You can just use the 'in' operator to find if a word is in the text. Example: print("Hello" in "Hello World") >> True
11th Feb 2021, 3:59 PM
noteve
noteve - avatar
+ 1
Using lambdas: text = input() word = input() search = lambda text, word : 'Word found' if word in text else 'Word not found' print(search(text, word)) Without lambdas: text = input() word = input() def search(text,word): return 'Word found' if word in text else 'Word not found' print(search(text, word))
20th Aug 2021, 10:19 AM
David GarcĂ­a Prados
0
I still need some detailed explanation in the "Search Engine" project. I can't get thru
12th Feb 2021, 4:11 AM
Sarvam Fating
Sarvam Fating - avatar
0
Sarvam Fating We're ready to help, just show us your code attempt so far so we may know the problem. Thanks.
12th Feb 2021, 4:18 AM
noteve
noteve - avatar
0
Thanks I'll post it in a while
12th Feb 2021, 4:19 AM
Sarvam Fating
Sarvam Fating - avatar
0
def search(text,word) if (text.count(word)==1) print("Word found") else: print("Word not found") print(search(text,word) I'm sorry if I've messed it up big time, I'm totally new at coding 😭
12th Feb 2021, 5:19 AM
Sarvam Fating
Sarvam Fating - avatar
0
Thank you sooo much đŸ„ș❀I'll keep that in mind, have a good day
12th Feb 2021, 5:29 AM
Sarvam Fating
Sarvam Fating - avatar
0
Sarvam Fating I forgot to mention. In our 'if' condition, we can just use the 'in' operator to check if that string is inside the other string. ( See the code 'Your Code 159' ) Though your condition 'text.count(word) == 1' is almost right, just have to make it 'word.count(text)' adjust it a little but because the substring may appear 2 or more times. if (word.count(text) >= 1)
12th Feb 2021, 5:33 AM
noteve
noteve - avatar
0
Sarvam Fating You're Welcome! You too, Have a Good Day!
12th Feb 2021, 5:33 AM
noteve
noteve - avatar
0
Yes I'll check it out
12th Feb 2021, 5:35 AM
Sarvam Fating
Sarvam Fating - avatar
0
Thank you so much , the code worked perfectly
12th Feb 2021, 6:22 AM
Sarvam Fating
Sarvam Fating - avatar