Найти - Пользователи
Полная версия: Помоги мне
Начало » Центр помощи » Помоги мне
1
palimpsests
I have line ‘pythonpythonpyth’. How do I know which word is the foundation line?.
Other examples:
“hellohellohellohello” –> hello
“DOLORIUMD” –> DOLORIUM
“HELLOL” –> HELLOL
“thewordword” –> thewordword

I need to know whether the word in the text is repeated and get it. This will be the key.
py.user.next
>>> def f(s):
...     i = s.find(s[0], 1)
...     return (i > 0 and s[:i]) or s
... 
>>> f('hellohellohellohello')
'hello'
>>> f('DOLORIUMD')
'DOLORIUM'
>>> f('HELLOL')
'HELLOL'
>>> f('thewordword')
'thewordword'
>>>

Там, возможно, нужно проверять повторяемость слова. Чтобы для hellohehellohe выдавало hellohe, а не hello.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB