I need algorithm for my task

C@rlos cmferras at estudiantes.uci.cu
Wed Nov 5 19:05:15 CET 2014


I thing this work: 

stg='pythonpython' 
foundationline=stg[ 0:( stg [ 1: ].index( stg[ 0 ])+1 ) ] 

On 2014-11-05 11:58, lordvital21 at 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. 
> 
Consider the first example. 

If the foundation is the first 1 character 'p' and you repeat it enough 
times you'll get 'pppppppppppppppp'. 

This is the same length as the line. 

Does it match the line? No. 

OK. 

If the foundation is the first 2 characters 'py' and you repeat it 
enough times you'll get 'pypypypypypypypy'. 

This is the same length as the line. 

Does it match the line? No. 

OK. 

If the foundation is the first 3 characters 'py' and you repeat it 
enough times you'll get 'pytpytpytpytpytpyt'. 

This is longer than as the line, so truncate it to 'pytpytpytpytpytpy'. 

Does it match the line? No. 

OK. 

Continue in this vein until you'll get a match. (The foundation might 
in fact be the entire line.) 

-- 
https://mail.python.org/mailman/listinfo/python-list 

III Escuela Internacional de Invierno en la UCI del 17 al 28 de febrero del 2014. Ver www.uci.cu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20141105/35d5942e/attachment.html>


More information about the Python-list mailing list