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: 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: References: <1962053862.5573720.1415210715670.JavaMail.zimbra@estudiantes.uci.cu> Date: Thu, 6 Nov 2014 15:14:05 +1100 Subject: Re: I need algorithm for my task 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: 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 On Thu, Nov 6, 2014 at 3:00 PM, Denis McMahon 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