So, you have two lists: a list of words that you want to check and possibly delete, and a list of valid words. If you like, you can use the same list for both purposes, but I assume that you have two lists.
. , - . , . "a" "I" , , "a", , ?
/usr/share/dict/words Ubuntu. ; , , , . , "k" "q", "z" .. , , , , - . , .
:
wfile = "/usr/dict/share/words"
valid = set(line.strip() for line in open(wfile) if len(line) >= 3)
lst = ["ark", "booze", "kite", "live", "rodeo"]
def subwords(word):
for i in range(len(word) - 1, 0, -1):
w = word[:i]
yield w
newlst = []
for word in lst:
if not any(w in valid for w in subwords(word)):
newlst.append(word)
print(newlst)
, "" :
newlst = [word for word in lst if not any(w in valid for w in subwords(word))]
, , , , .
, , , :
def keep(word):
return not any(w in valid for w in subwords(word))
newlst = [word for word in lst if keep(word)]
Python , , .