Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!weretis.net!feeder4.news.weretis.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'key.': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'repeated': 0.09; 'python': 0.11; 'examples:': 0.16; 'occurences': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'repetition': 0.16; 'wrote:': 0.18; 'any,': 0.19; 'split': 0.19; 'subject:need': 0.19; 'foundation': 0.20; 'header:User- Agent:1': 0.23; 'header:X-Complaints-To:1': 0.27; 'rest': 0.29; "skip:' 10": 0.31; '(possibly': 0.31; 'letter.': 0.31; 'text': 0.33; 'there': 0.35; 'false': 0.36; "didn't": 0.36; 'implement': 0.38; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'simple': 0.61; 'first': 0.61; 'email addr:gmail.com': 0.63; 'fifa': 0.84 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: I need algorithm for my task Date: Wed, 05 Nov 2014 13:36:17 +0100 Organization: None References: <50a7df31-ee6c-45f5-9dd8-6ac895ec46cf@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bd9e98.dip0.t-ipconnect.de User-Agent: KNode/4.13.3 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: 33 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415190991 news.xs4all.nl 2947 [2001:888:2000:d::a6]:59581 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80268 lordvital21@gmail.com wrote: > I have line 'pythonpythonpyth'. How do I know which word is the foundation > line?. Other examples: > "pythonpythonpyth" is python > "DOLORIUMD" is DOLORIUM > "HELLOLHELLO" is HELLOL > "thewordword" is thewordword > > I need to know whether the word in the text is repeated and get it. This > will be the key. A simple approach that might work (I didn't implement it to verify): Look for other occurences of the first letter. If there are none you have the "foundation", if there are any, split the line before them and check if the rest of the line can be constructed as a (possibly truncated) repetition of the beginning. For fifafofifaf you'd have to check fi fafofifaf --> false fifa fofifaf --> false fifafo fifaf --> true so we don't care about fifafofi faf fifafofifa f