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


Groups > comp.lang.python > #80272

Re: I need algorithm for my task

From Denis McMahon <denismfmcmahon@gmail.com>
Newsgroups comp.lang.python
Subject Re: I need algorithm for my task
Date 2014-11-05 15:19 +0000
Organization A noiseless patient Spider
Message-ID <m3df6b$dhn$2@dont-email.me> (permalink)
References <50a7df31-ee6c-45f5-9dd8-6ac895ec46cf@googlegroups.com>

Show all headers | View raw


On Wed, 05 Nov 2014 03:58:33 -0800, lordvital21 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.

Well, the way you describe it:

So first you want to check if the first letter is also the second letter
Then you want to check if the first 2 letters are also the 3rd and 4th
Then you want to check if the first 3 letters are also the 4th-6th
Then you want to check if the first 4 letters are also the 5th-8th

So generally you want to check if the first n letters are also the second 
n letters, increasing n by 1 at a time until you reach your terminating 
condition.

So what is your terminating condition? I can see two possibilities. You 
run out of letters in the second section, or you find a match.

Here are a few more hints to help get you started:

A string is a list of characters.
A list can be sliced.
You can measure the length of a list.
You can compare the lengths of two lists.
You can compare two lists.
You can get the length of a string.
The maximum length of a repeated word in a string can not be more than 
half the length of the string.

However, the examples you give do not match the way you describe it. The 
examples you give assume the first word ends when the letter that started 
it is found again.

-- 
Denis McMahon, denismfmcmahon@gmail.com

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


Thread

I need algorithm for my task lordvital21@gmail.com - 2014-11-05 03:58 -0800
  Re: I need algorithm for my task Chris Angelico <rosuav@gmail.com> - 2014-11-05 23:29 +1100
    Re: I need algorithm for my task Darren Chen <ccylily1314@gmail.com> - 2014-11-06 17:42 -0800
  Re: I need algorithm for my task Peter Otten <__peter__@web.de> - 2014-11-05 13:36 +0100
  Re: I need algorithm for my task Denis McMahon <denismfmcmahon@gmail.com> - 2014-11-05 15:19 +0000
  Re: I need algorithm for my task MRAB <python@mrabarnett.plus.com> - 2014-11-05 17:53 +0000
  Re: I need algorithm for my task wxjmfauth@gmail.com - 2014-11-05 11:07 -0800
    Re: I need algorithm for my task wxjmfauth@gmail.com - 2014-11-05 11:29 -0800
      Re: I need algorithm for my task wxjmfauth@gmail.com - 2014-11-05 22:31 -0800

csiph-web