Python: Getting the Index of a list -


i'm trying create program take input of sentence , word , check sentence word , return index of beginning of word i.e.

sentence = "random set of words"       word = "of"      result = 9 

this tried

sentence = (input("enter sentence: ")) word = (input("enter word: "))  result = sentence.split()  x in sentence:   if x == (word):     boom = enumerate(word) print(boom) 

assuming word appears once, i'd this:

sentence = sentence.split(word) sentence[0] = sentence[0].replace(" ","") result = len(sentence[0]) 

Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -