+ 4

Can anyone tell me how this code works.

It prints the words that contain the letter that's been input....but how?i dont know how this worked pls tell me. https://code.sololearn.com/cm75gh58Q8z5/?ref=app

16th Dec 2022, 7:20 PM
Shoto-todoroki69
Shoto-todoroki69 - avatar
15 ответов
+ 3
It checks whether the provided stirng (command) of input is existed in given list (words) or not. Returns the same stirng if it exist.no output otherwise.
17th Dec 2022, 9:36 AM
Nakka Sunil
+ 2
words = ["cat", "car", "code", "home", "learn", "fun", "job", "love", "friend", "zoo", "enjoy", "happiness", "family", "goal", "desire"] #your code goes here command = input() if command in words: print(command ) else: print(command ,": not found in words ") Here made it better....
18th Dec 2022, 5:04 PM
FurQan
FurQan - avatar
+ 1
Thanks...but im still not clear though
16th Dec 2022, 7:45 PM
Shoto-todoroki69
Shoto-todoroki69 - avatar
+ 1
You took had a variable containing an array.. After that you took an input which is command You looped through the array by saying telling python interpreter that "Hey,look at these stuffs in my array ," You then gave the interpreter another condition that "If this input Is in my array, please print out this input." "But if it's not in my array,print nothing!" That's what happened in that code. Hope this helped?
16th Dec 2022, 9:41 PM
Emmanuel Ndema
Emmanuel Ndema - avatar
+ 1
I don't know anything about that coding:D
18th Dec 2022, 10:53 AM
Esan Mosharof Esan
Esan Mosharof Esan - avatar
+ 1
First we have a list called words and then it takes an input command = input() for i in words: i is the item in the words if command in i: print(i) It will iterate through the list this means the items in the words will be in the "i" so if python find the command in the "i" it will print it
18th Dec 2022, 10:55 AM
Abemelek Ermias
Abemelek Ermias - avatar
+ 1
if i in words, i mean.
18th Dec 2022, 11:30 AM
Willem van Dorland
Willem van Dorland - avatar
0
Ok
16th Dec 2022, 8:11 PM
Shoto-todoroki69
Shoto-todoroki69 - avatar
0
Oh ok i understand now thank you
17th Dec 2022, 3:07 AM
Shoto-todoroki69
Shoto-todoroki69 - avatar
0
You are getting the input from user. Then you are iterating the list and checking if the input is present. If it is, then you printing the input.
18th Dec 2022, 9:57 AM
Kishore Kumar
0
words = ["cat", "car", "code", "home", "learn", "fun", "job", "love", "friend", "zoo", "enjoy", "happiness", "family", "goal", "desire"] #your code goes here for i in words: if in words: print(i) This is your right code. The i itters the list til the end. While the print(i) prints the words out.
18th Dec 2022, 11:27 AM
Willem van Dorland
Willem van Dorland - avatar
0
Ok thanks for the explanation
18th Dec 2022, 11:32 AM
Shoto-todoroki69
Shoto-todoroki69 - avatar
0
It should be <<if command == i>> and not <<if command in i>> because if someone input letter "a" it will output all "a" characters in every word containing the letter "a" Just run your current code and input "a" to understand the nuance.
18th Dec 2022, 3:24 PM
iTech
iTech - avatar