Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #63546
| References | <x4jwu.3413$Bs5.1921@fx09.am4> <mailman.4725.1388433616.18130.python-list@python.org> <P6hzu.2028$Wn7.1602@fx20.am4> <vcprc9l33287s827e421tbib9tvlkb0pb1@4ax.com> |
|---|---|
| Date | 2014-01-09 11:21 +1100 |
| Subject | Re: Dictionary |
| From | Chris Angelico <rosuav@gmail.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5217.1389226906.18130.python-list@python.org> (permalink) |
On Thu, Jan 9, 2014 at 11:13 AM, Dennis Lee Bieber
<wlfraed@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
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Dictionary Bischoop <martin@jakis.adres.em> - 2013-12-30 18:38 +0000
Re: Dictionary Walter Hurry <walterhurry@gmail.com> - 2013-12-30 18:56 +0000
Re: Dictionary Bischoop <martin@jakis.adres.em> - 2014-01-08 19:00 +0000
Re: Dictionary wxjmfauth@gmail.com - 2014-01-09 00:31 -0800
Re: Dictionary Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-30 15:00 -0500
Re: Dictionary Bischoop <martin@jakis.adres.em> - 2014-01-08 18:51 +0000
Re: Dictionary Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-08 19:13 -0500
Re: Dictionary Chris Angelico <rosuav@gmail.com> - 2014-01-09 11:21 +1100
csiph-web