I think I figured out what you want:
#!/usr/bin/env python2
def give():
result = []
with open('words2.txt', mode='rt') as fin:
for line in fin:
result += line.split()
return result
def enter(forbid):
words = give()
for w in words:
if all([letter not in forbid for letter in w]):
print w
enter("bcdfghjklmst")
using this lorem ipsum (i.e. content from words2.txt):
Eum dicta nihil iste quo minima repudiandae possimus. Provident nam
explicabo ut accusantium odit voluptatibus. Animi dolor sit deserunt
quisquam perspiciatis aut et voluptas. Repellat quo accusamus sint.
Tempore vero iste rerum. Harum aut rerum qui rerum quis dolores
perspiciatis. Quas sed necessitatibus et rerum eum culpa. Autem
delectus aut sunt ab officiis sit non voluptatum. Id sequi voluptas
qui quo officia officiis placeat voluptatem.
Nemo ipsa illo amet deleniti. Praesentium voluptatum voluptate
mollitia quod voluptates beatae. Doloremque molestias nostrum iste
possimus veritatis repellendus et dolor. Quidem sit iusto autem et id
dicta ut.
Ad earum incidunt officia ea. Et quidem molestiae et facere. Culpa
harum veniam illum. Culpa quod porro in et eos adipisci. Sint
accusantium est qui inventore minima perferendis. Autem quidem omnis
et quia error enim nam.
Distinctio velit ut facere animi delectus. Et deleniti expedita earum
nesciunt voluptas ea. In asperiores a nobis occaecati quam qui
repellendus molestiae. Excepturi distinctio consequatur commodi est
velit sit. Sit soluta a adipisci aut. Eos voluptatibus enim corrupti.
output (all word not containing any letter from "bcdfghjklmst"):
$ ./test_script2.py
quo
quo
vero
qui
non
qui
quo
ea.
porro
in
qui
quia
error
ea.
In
a
qui
a
Explanation:
give() collects the words in a single list and returns them all
- inside
give(), a with statement is used to ensure the file is properly handled (closed at the end...)
for w in words browses all the words from the list
[letter not in forbid for letter in w] is a comprehension list that contains booleans only. For each letter of the current examined word (i.e. w), it will put True if the letter does not belong to forbid. all() is True only if all the booleans from the list are True, so only if all letters of w do not belong to forbid
- the last part could be shortened
like this:
def enter(forbid):
for w in give():
if all([letter not in forbid for letter in w]):
print w