Уведомления

Группа в Telegram: @pythonsu

#1 Ноя. 5, 2014 16:15:51

palimpsests
Зарегистрирован: 2014-11-05
Сообщения: 1
Репутация: +  0  -
Профиль   Отправить e-mail  

Помоги мне

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.

Офлайн

#2 Ноя. 5, 2014 22:45:22

py.user.next
От:
Зарегистрирован: 2010-04-29
Сообщения: 9894
Репутация: +  854  -
Профиль   Отправить e-mail  

Помоги мне

>>> 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.



Отредактировано py.user.next (Ноя. 5, 2014 22:46:13)

Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version