user325923 user325923 - 7 months ago 18
Python Question

search letters from wordlist and print words

i already created this program but facing some error . its showing those words which contain any letter from user input but i want it should search all letter in a word :
my code is

life=open('/Users/tim/Desktop/words.txt')
dds=str(input())
for list in life:
index=0


if dds[index] in list:
print(list)
index=index+1


which modifications i have to do so it can search as i want ?

and also i tried this :

life=open('/Users/tim/Desktop/words.txt')
dds="er"
for list in life:
index=0


if dds[index] in list:
print(list)
index=index+1


now i wanted it should print all words containing word "e"

Answer

try this :

if dds[index:] in list:

you were doing : if dds[index] in list: it means it will print all words which contains any letter of "dds" in word in wordlist . if you try this : if dds[index:] in list: it will search all letter of word in wordlist . [:] will select all letters

a[start:end] # items start through end-1
a[start:]    # items start through the rest of the array
a[:end]      # items from the beginning through end-1
a[:]         # a copy of the whole array
Comments