Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed2.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.007 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'algorithm': 0.04; 'string': 0.09; 'key.': 0.09; 'repeated': 0.09; 'cc:addr:python- list': 0.11; 'python': 0.11; 'examples:': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'code.': 0.18; 'wed,': 0.18; 'subject:need': 0.19; 'later': 0.20; 'foundation': 0.20; 'code,': 0.22; 'cc:addr:python.org': 0.22; 'lets': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'header:In-Reply-To:1': 0.27; 'on,': 0.29; 'message- id:@mail.gmail.com': 0.30; "skip:' 10": 0.31; 'there.': 0.32; 'probably': 0.32; 'text': 0.33; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'next': 0.36; 'starting': 0.37; 'nov': 0.38; 'pm,': 0.38; 'how': 0.40; 'letters': 0.60; 'simple': 0.61; 'first': 0.61; 'back': 0.62; 'making': 0.63; '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=2Gei+9CtAIyG4n//4amYbbKgNmqfYY5K2OpQ0GlI1Ic=; b=f2yG6uD5oFUzfEVoeWaqfe1wDU93oQpN3qGvKmj8aTceN5Za4czSg52Iz+yxX4azEn rBpFLr4SLS4XSvWXeIqSpv9PG1f9wAYJ/LjiNaVmIOks1LAUh3Ll8KOSNmYso1CE3lKD 0v6lRMOfkGFKP4yVUOKr+CkzAYmZVfQjdY0ylzxuik+qaUfKGFdRqPeIm/wmOtMWxk8z fRM3zJUbCFJf78GwnS7GNrhWoGx+MFsqJmxZmxD9TlNT91PZ0QhvUv9rDoMkSuyLeEoH nFCTgg736lWykeNNLJw6rLZiGf0a9TG0jGjZevw3eqiKkLq7gZ2emDRATXmiYasNkwy+ evxA== MIME-Version: 1.0 X-Received: by 10.42.37.138 with SMTP id y10mr4198009icd.26.1415190571400; Wed, 05 Nov 2014 04:29:31 -0800 (PST) In-Reply-To: <50a7df31-ee6c-45f5-9dd8-6ac895ec46cf@googlegroups.com> References: <50a7df31-ee6c-45f5-9dd8-6ac895ec46cf@googlegroups.com> Date: Wed, 5 Nov 2014 23:29:31 +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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1415190574 news.xs4all.nl 2909 [2001:888:2000:d::a6]:54192 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:80266 On Wed, Nov 5, 2014 at 10:58 PM, 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. This sounds like it's probably homework, so I won't actually give you the code, just a starting hint. Python lets you slice a string to get back a substring. Start with a really simple algorithm like "see if the first N letters are also the next N letters and so on until you pass the end of the string", then word that up into Python code. Later on, you can look into making it less naive, but start simple and work up from there. ChrisA