Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80313

Re: I need algorithm for my task

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.099
X-Spam-Evidence '*H*': 0.82; '*S*': 0.02; 'elegant': 0.07; 'cc:addr :python-list': 0.11; 'def': 0.12; 'algorithm.': 0.16; 'bit.': 0.16; 'doing,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'subject:need': 0.19; 'thu,': 0.19; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'header:In-Reply-To:1': 0.27; 'characters': 0.30; 'message- id:@mail.gmail.com': 0.30; 'but': 0.35; 'received:google.com': 0.35; 'sequence': 0.36; 'nov': 0.38; 'pm,': 0.38; 'took': 0.61; 'love': 0.65; 'close': 0.67; 'compliant': 0.68; 'line,': 0.68; 'skip:r 30': 0.69; 'analysis': 0.75; '3:00': 0.84; 'hardly': 0.84; 'partial': 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=YJRHcnNCfFMG56FAuQAfnoRo8V+QLAhDUfrN7sO3PZc=; b=k3Rv+wqy3Oc25+VZsMHSvy5tWwsEtm/MkzDBh9vq81/qKeP3pN+TKMvC2wLlceL7/J QWubBVegoWng5Q+4UHkoC18n0NfHTwOGMJXCFjr3xJSGgiK/H1HPg0xy4okSiVrWw/i2 F3bRT8JfsKNFWUf2I3GWvlyOV+ZU6XQ6mi6cb7lfybGH+2y6CJ8ZbAEqAcpSAmLX5763 wKexZzoXFIM7uZHvPIV/ydefokbms3RulCAkwKYexgO2/nXtFnO8oN2/hXf4V0BLzBJX 7TOiVnBRvsRciWt7YXj0q6olui7GgV9HErETVQ/BAjUAr0j1mxO/6sZJOObgGWlnqhYy 3uxw==
MIME-Version 1.0
X-Received by 10.42.103.2 with SMTP id k2mr8940467ico.46.1415247245461; Wed, 05 Nov 2014 20:14:05 -0800 (PST)
In-Reply-To <m3erp6$dhn$9@dont-email.me>
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>
Date Thu, 6 Nov 2014 15:14:05 +1100
Subject Re: I need algorithm for my task
From Chris Angelico <rosuav@gmail.com>
Cc "python-list@python.org" <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 <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.15534.1415247248.18130.python-list@python.org> (permalink)
Lines 18
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1415247248 news.xs4all.nl 2892 [2001:888:2000:d::a6]:43185
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:80313

Show key headers only | View raw


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.

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.

ChrisA

Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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