Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!news.tele.dk!feed118.news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'pat': 0.05; 'class,': 0.07; 'trailing': 0.09; 'cc:addr:python-list': 0.11; 'jan': 0.12; 'class).': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ought': 0.16; 'supplied': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; 'sort': 0.25; 'skip:" 30': 0.26; 'header:In-Reply-To:1': 0.27; 'am,': 0.29; 'character': 0.29; 'message- id:@mail.gmail.com': 0.30; "i'm": 0.30; 'pipe': 0.31; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'representing': 0.36; 'skip:[ 10': 0.38; 'anything': 0.39; 'sure': 0.39; 'expression': 0.60; 'letters': 0.60; 'skip:o 30': 0.61; 'simply': 0.61; 'significance': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=rirNA3o4/EhO/yPb9Oj9jdENoo5vwOnV1YwkkucUmyI=; b=zDqcPQdUi4b22LSd/VN8gMLThLqPOKdysUoegLn/Peuo+/7RjwXJbD+zgkVPgdpdq+ LXvQzo0vke7MyY3qWxMyoASpgWUxxu63kL1uRkuLVw1OMG9Fl6+lr3mXQ5wHq91a10A3 OvN/HOHeaQ7pCoCwPQY6pgBSrzNJ5N1wiubeskb7DeTy2KKT6vT+YthZt1FWCO7O2ry1 vLeAEK7W3H7MFb83Tx3OTRO4GDOL83MpWjysFOKxtvL0HTgL+SDFSEkiLLyM7oEF/HJg SQvqdLTxtXeOm2ctxPN3/s3yZRQSFBMcrGvWrjGSUM6V6JjoK5mqICfb2TGAPF6K7Khw T8kw== MIME-Version: 1.0 X-Received: by 10.66.118.71 with SMTP id kk7mr183167pab.14.1389226903508; Wed, 08 Jan 2014 16:21:43 -0800 (PST) In-Reply-To: References: Date: Thu, 9 Jan 2014 11:21:43 +1100 Subject: Re: Dictionary From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 19 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1389226906 news.xs4all.nl 2886 [2001:888:2000:d::a6]:46477 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:63546 On Thu, Jan 9, 2014 at 11:13 AM, Dennis Lee Bieber 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