#---Input data #List of words; every word or sentence on one line #If from file: WORDS = open(fileName).readlines() WORDS = """\ Afrikaans Anna Bread red word bored python""".split('\n')
#---Main program import re PATTERN = ['[^(%s)]+','[%s]+'] FILENAME = ['not_%s.txt','%s.txt'] def filter(letters='bdeor',words=WORDS,contain=True,ignoreCase=True): pattern = PATTERN[contain]%'|'.join(list(letters)) if ignoreCase: allowed = re.compile(pattern,re.IGNORECASE) else: allowed = re.compile(pattern) result = [] for word in words: match = allowed.match(word) if match and match.group(0) == word: result.append(word) print result output = open(FILENAME[contain]%letters,'w') output.write('\n'.join(result)) output.close() if __name__ == '__main__': filter() --------------- This should do it. Stani -- http://pythonide.stani.be http://pythonide.stani.be/manual/html/manual.html -- http://mail.python.org/mailman/listinfo/python-list