ender ender - 1 year ago 105
Python Question

How to find a word in a list

so my program will require the user to input a phrase WITHOUT punctuation and the program will return its position in the list.

def Detection():
list = input("Enter a phrase without punctuation:")
list = list.split(" ")
list = [element.lower() for element in list]
find=input("what word must be found?")
if find in list:
for find in list:
print("its not in the list.")

Answer Source

i found a way here it is.

sentence =input("phrase to be shortened: ")
print (sentence)
text = input("Choose a word from the sentence above: ")
sentence = sentence.upper()
sentence = sentence.split(" ")
text = text.upper ()# this makes the text in capital letters
def lookfor (text):
    indexes = [ idx+1 for word, idx in zip(sentence, range(0,len(sentence))) if text == word ]
    print ("Your word has been found in the sentence at these positions", indexes )

    if not indexes:
         print ("The word that you have typed is not found in the sentence.")

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download