On Thu, Jan 9, 2014 at 11:13 AM, Dennis Lee Bieber <wlfr...@ix.netcom.com> wrote: > #generate search re expression representing > # .* any character/multiple -- leading > # [l|e|t|t|e|r] match any of the letters supplied > # .* any character/multiple -- trailing > needle = ".*[" + "|".join(list(letters.lower())) + "].*"
I don't think this will do what you think it will. It'll match anything that has any one of the supplied letters (or a pipe; it's a character class, so the pipe has no significance and is simply part of the class). I'm not sure a regex is the best thing here; but what you could do is sort the letters and sort the letters in the words: pat = ".*".join(sorted(letters.lower())) for word in open("/usr/share/dict/words"): # Ought to use with if re.search(pat, ''.join(sorted(word))): print(word) ChrisA -- https://mail.python.org/mailman/listinfo/python-list