|
发表于 2021-7-17 07:32:42
|
显示全部楼层
- #!/usr/bin/python
- import re
- s='''Hmm~ There's a hero If you look inside your heart You don't have to be afraid
- Of what you are There's an answer If you reach into your soul
- And the sorrow that you know Will melt away And then a hero comes along
- With the strength to carry on And you cast your fears aside
- And you know you can survive So when you feel like hope is gone
- Look inside you and be strong And you'll finally see the truth
- That a hero lies in you abcdeabcde It's a long road When you face the world alone
- No one reaches out a hand or you to hold You can find love
- If you search within yourself And the emptiness you felt will disappear
- And then a hero comes along With the strength to carry on And you cast your fears aside
- And you know you can survive So when you feel like hope is gone
- Look inside you and be strong And you'll finally see the truth
- That a hero lies in you Lord knows......Dreams are hard to follow
- '''
- def k(s):
- result=""
- l=list( set(re.findall(r'(\w{2,})', s)))
- z=sorted(l,key=lambda l: len(l))
- result=z[-1]
- a=len(z.pop())
- for i in z[::-1]:
- if (len(i)==a):
- result=result+","+i
- else:
- return result
- print(k(s))
复制代码 |
|