I need algorithm for my task
Denis McMahon
denismfmcmahon at gmail.com
Wed Nov 5 22:14:16 EST 2014
On Wed, 05 Nov 2014 18:49:01 +0000, MRAB wrote:
> On 2014-11-05 18:05, C at rlos wrote:
>> I thing this work:
>>
>> stg='pythonpython'
>> foundationline=stg[ 0:( stg [ 1: ].index( stg[ 0 ])+1 ) ]
>>
> It doesn't work for the final example or "barbaz".
I have two algorithms I've implemented.
Still not sure exactly which algorithm he wants though. The first one is
as he describes, in that the word is only reported if it's repeated, else
report the whole string.
The second algorithm reads up until the first letter is repeated, or
reports the whole string if no repeat found.
I did see a third algorithm suggested, I should add that and see what
happens.
OK, implemented the third algorithm (repeat first n chars of s int(n/len
(s))+1 times, truncate to len(s) and compare with s), I also added
another test case, now my test cases are:
t = ["pythonpythonpyth", "DOLORIUMD", "HELLOLHELLO", "thewordword",
"barbaz", "dibdibdobdibdibdob"]
and my output is:
$ ./words.py
python DOLORIUMD HELLOLHELLO thewordword barbaz dib
python DOLORIUM HELLOL thewordword bar dib
python DOLORIUM HELLOL thewordword barbaz dibdibdob
$
I wonder which of these three is actually the algorithm the OP wants.
--
Denis McMahon, denismfmcmahon at gmail.com
More information about the Python-list
mailing list