Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #60271
| Path | csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!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 | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.019 |
| X-Spam-Evidence | '*H*': 0.96; '*S*': 0.00; 'algorithm': 0.04; 'url:pipermail': 0.05; 'string': 0.09; 'dan': 0.09; 'exist,': 0.09; 'input,': 0.09; 'repeated': 0.09; 'sentence': 0.09; 'def': 0.12; '(),': 0.16; 'already,': 0.16; 'for,': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'generators.': 0.16; 'merely': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'redundant': 0.16; 'remainder': 0.16; 'subject:combinations': 0.16; 'subject:generator': 0.16; 'fix': 0.17; 'wrote:': 0.18; 'wed,': 0.18; 'all,': 0.19; 'thu,': 0.19; 'fit': 0.20; 'input': 0.22; 'header:User-Agent:1': 0.23; 'filtering': 0.24; 'header:In-Reply- To:1': 0.27; 'words': 0.29; 'characters': 0.30; "i'm": 0.30; 'reply.': 0.31; "skip:' 10": 0.31; 'away.': 0.31; 'lot.': 0.31; 'this.': 0.32; 'probably': 0.32; 'says': 0.33; 'url:python': 0.33; 'problem': 0.35; 'but': 0.35; 'there': 0.35; 'opposed': 0.36; 'words,': 0.36; 'yield': 0.36; 'thanks': 0.36; 'subject:?': 0.36; 'url:org': 0.36; 'should': 0.36; 'two': 0.37; 'problems': 0.38; 'nov': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'rather': 0.38; 'short': 0.38; 'anything': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'how': 0.40; 'even': 0.60; 'most': 0.60; 'john': 0.61; 'here:': 0.62; "you'll": 0.62; 'story': 0.63; 'interest': 0.64; 'more': 0.64; 'fire': 0.65; 'here': 0.66; 'header:Reply- To:1': 0.67; '20,': 0.68; 'combining': 0.68; 'subject': 0.69; 'results': 0.69; 'containing': 0.69; 'reply-to:no real name:2**0': 0.71; 'characters,': 0.84; 'recursive.': 0.84; 'reply- to:addr:python.org': 0.84; 'story:': 0.84; 'incredibly': 0.96; '2013': 0.98 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=C6LQl2/+ c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=OJn0C7AadrgA:10 a=arCsX2pBBRkA:10 a=ihvODaAuJD4A:10 a=OUOv7kDek9cA:10 a=8nJEP1OIZ-IA:10 a=EBOSESyhAAAA:8 a=8AHkEIZyAAAA:8 a=YIRIjkhCr0AA:10 a=pGLkceISAAAA:8 a=o0UQg2zDAAAA:8 a=9buDmM57gjZXuERJbMMA:9 a=wPNLvfGTeEIA:10 a=rORHjrSJJG4A:10 a=MSl-tDqOz04A:10 a=VpnQFi2keKsA:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Sat, 23 Nov 2013 04:23:42 +0000 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 5.1; rv:24.0) Gecko/20100101 Thunderbird/24.1.1 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: Recursive generator for combinations of a multiset? |
| References | <20131121174614.53450d51@mini.home> <CAGGBd_oz8B8bU5SfTdbq7kAU0yM05WktHQ4GGwJrwNBQDZMi_A@mail.gmail.com> <20131123115838.4016c671@mini.home> |
| In-Reply-To | <20131123115838.4016c671@mini.home> |
| Content-Type | text/plain; charset=ISO-8859-1; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| Reply-To | python-list@python.org |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3067.1385180625.18130.python-list@python.org> (permalink) |
| Lines | 55 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1385180625 news.xs4all.nl 15878 [2001:888:2000:d::a6]:40770 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:60271 |
Show key headers only | View raw
On 23/11/2013 00:58, John O'Hagan wrote: > On Thu, 21 Nov 2013 12:59:26 -0800 > Dan Stromberg <drsalists@gmail.com> wrote: > >> On Wed, Nov 20, 2013 at 10:46 PM, John O'Hagan >> <research@johnohagan.com>wrote: >> >> > >> > Short story: the subject says it all, so if you have an answer >> > already, fire away. Below is the long story of what I'm using it >> > for, and why I think it needs to be recursive. It may even be of >> > more general interest in terms of filtering the results of >> > generators. >> > >> >> I think you probably need permutations rather than combinations. >> >> Also, I think you'll need to form a word (partitioned off by spaces), >> and then check it against a set containing /usr/share/dict/words >> before recursing for the remainder of the sentence - this should >> speed things up a LOT. > > Thanks for the reply. If I understand you correctly, you are suggesting > permuting the input _characters_ to form words and then seeing if > they exist, as opposed to my approach of combining known words and > seeing if they are anagrams. (Permutations of words would not help find > anagrams as they merely change the word order). Here is an attempt at > that: > > def anagrams(partition, input_string): > """Find anagrams which fit given partition of input string length""" > if not partition: > yield (), input_string > return > for words, checkstring in anagrams(partition[:-1], input_string): > for word in itertools.permutations(checkstring, partition[-1]): > word = ''.join(word) > if word in WORDS: #WORDS is collection of dictionary words > newstring = checkstring > for l in word: > newstring = newstring.replace(l, '' , 1) > yield words + (word,), newstring > > There are two problems with this. If there are repeated characters in > the input, redundant results are produced; a multiset-permutation > algorithm would fix this. But the main problem is it is incredibly > slow: on my run-of-the-mill laptop, it chokes on anything longer than > about 10 characters, spending most of its time rejecting non-words. > > Or have I misunderstood your suggestion? > If you want to know how to get unique permutations, have a look here: http://mail.python.org/pipermail/python-ideas/2013-October/023610.html
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Recursive generator for combinations of a multiset? MRAB <python@mrabarnett.plus.com> - 2013-11-23 04:23 +0000
csiph-web