Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #80314
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!eternal-september.org!feeder.eternal-september.org!mx02.eternal-september.org!.POSTED!not-for-mail |
|---|---|
| From | Denis McMahon <denismfmcmahon@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: I need algorithm for my task |
| Date | Thu, 6 Nov 2014 04:39:38 +0000 (UTC) |
| Organization | A noiseless patient Spider |
| Lines | 34 |
| Message-ID | <m3eu2a$dhn$11@dont-email.me> (permalink) |
| References | <1962053862.5573720.1415210715670.JavaMail.zimbra@estudiantes.uci.cu> <mailman.15514.1415213345.18130.python-list@python.org> <m3eqc8$dhn$8@dont-email.me> <m3erp6$dhn$9@dont-email.me> <mailman.15534.1415247248.18130.python-list@python.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| Content-Transfer-Encoding | 8bit |
| Injection-Date | Thu, 6 Nov 2014 04:39:38 +0000 (UTC) |
| Injection-Info | mx02.eternal-september.org; posting-host="66ffcfa4470a58bcddbdcd1913f98ab4"; logging-data="13879"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19p9vbUa4lKA2YwWlvAZXwQrpc3idKXJEo=" |
| User-Agent | Pan/0.136 (I'm far too busy being delicious; GIT 926a150 git://git.gnome.org/pan2) |
| Cancel-Lock | sha1:UgsJGHARS2iPRD+ewBFux2JrpHM= |
| Xref | csiph.com comp.lang.python:80314 |
Show key headers only | View raw
On Thu, 06 Nov 2014 15:14:05 +1100, Chris Angelico wrote: > On Thu, Nov 6, 2014 at 3:00 PM, Denis McMahon <denismfmcmahon@gmail.com> > wrote: >> def baseword(s): >> """find shortest sequence which repeats to generate s""" >> return s[0:["".join([s[0:x]for k in range(int(len(s)/x)+1)])[0:len >> (s)]for x in range(1,len(s)+1)].index(s)+1] > > That's hardly a PEP-8 compliant line, but I can help out a bit. > > return s[0:[(s[0:x]*(len(s)//x+1))[0:len(s)]for x in > range(1,len(s)+1)].index(s)+1] > > That's still 83 characters without indentation, but it's close now. l = len r = range but technically then it's no longer a one liner. > I love the algorithm. Took me a bit of analysis (and inspection of > partial results) to understand what your code's doing, but it's stupidly > elegant and elegantly stupid. :) Well yes, building that list is a stupid way to solve the problem, but I can't see another way to do it in one line. It's an implementation of my algorithm 3 (which I think you described) but working from the other end as it were. -- Denis McMahon, denismfmcmahon@gmail.com
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Re: I need algorithm for my task MRAB <python@mrabarnett.plus.com> - 2014-11-05 18:49 +0000
Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 03:14 +0000
Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 03:36 +0000
Re: I need algorithm for my task Chris Angelico <rosuav@gmail.com> - 2014-11-06 14:47 +1100
Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 04:00 +0000
Re: I need algorithm for my task Chris Angelico <rosuav@gmail.com> - 2014-11-06 15:14 +1100
Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-06 04:39 +0000
Re: I need algorithm for my task Jussi Piitulainen <jpiitula@ling.helsinki.fi> - 2014-11-06 09:59 +0200
Re: I need algorithm for my task wxjmfauth@gmail.com - 2014-11-06 00:57 -0800
csiph-web