http://tieba.baidu.com/p/554284778
1. def cleanword(word):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> cleanword('what?')
'what'
>>> cleanword('"now!"')
'now'
>>> cleanword('?+="word!,@$()"')
'word'
"""
2. def has_dashdash(s):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> has_dashdash('distance--but')
True
>>> has_dashdash('several')
False
>>> has_dashdash('critters')
False
>>> has_dashdash('spoke--fancy')
True
>>> has_dashdash('yo-yo')
False
"""
3. def extract_words(s):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> extract_words('Now is the time! "Now", is the time? Yes, now.')
['now', 'is', 'the', 'time', 'now', 'is', 'the', 'time', 'yes', 'now']
>>> extract_words('she tried to curtsey as she spoke--fancy')
['she', 'tried', 'to', 'curtsey', 'as', 'she', 'spoke', 'fancy']
"""
4. def wordcount(word, wordlist):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> wordcount('now', ['now', 'is', 'time', 'is', 'now', 'is', 'is'])
['now', 2]
>>> wordcount('is', ['now', 'is', 'time', 'is', 'now', 'is', 'the', 'is'])
>>> wordcount('time', ['now', 'is', 'time', 'is', 'now', 'is', 'is'])
['time', 1]
>>> wordcount('frog', ['now', 'is', 'time', 'is', 'now', 'is', 'is'])
['frog', 0]
"""
5. def wordset(wordlist):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> wordset(['now', 'is', 'time', 'is', 'now', 'is', 'is'])
['is', 'now', 'time']
>>> wordset(['I', 'a', 'a', 'is', 'a', 'is', 'I', 'am'])
['I', 'a', 'am', 'is']
>>> wordset(['or', 'a', 'am', 'is', 'are', 'be', 'but', 'am'])
['a', 'am', 'are', 'be', 'but', 'is', 'or']
"""
6. def longestword(wordset):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> longestword(['a', 'apple', 'pear', 'grape'])
5
>>> longestword(['a', 'am', 'I', 'be'])
2
>>> longestword(['this', 'that', 'supercalifragilisticexpialidocious'])
34
"""
5. def wordset(wordlist):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> wordset(['now', 'is', 'time', 'is', 'now', 'is', 'is'])
['is', 'now', 'time']
>>> wordset(['I', 'a', 'a', 'is', 'a', 'is', 'I', 'am'])
['I', 'a', 'am', 'is']
>>> wordset(['or', 'a', 'am', 'is', 'are', 'be', 'but', 'am'])
['a', 'am', 'are', 'be', 'but', 'is', 'or']
"""
6. def longestword(wordset):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> longestword(['a', 'apple', 'pear', 'grape'])
5
>>> longestword(['a', 'am', 'I', 'be'])
2
>>> longestword(['this', 'that', 'supercalifragilisticexpialidocious'])
34
"""
6. def longestword(wordset):
(用Python写出程序,使程序可以通过下面的doctest)
"""
>>> longestword(['a', 'apple', 'pear', 'grape'])
5
>>> longestword(['a', 'am', 'I', 'be'])
2
>>> longestword(['this', 'that', 'supercalifragilisticexpialidocious'])
34
"""
['is', 4]
7. def myreplace(old, new, s):
(用Python写出程序,使程序可以通过下面的doctest)
"""
Replace all occurances of old with new in the string s.
>>> myreplace(',', ';', 'this, that, and, some, other, thing')
'this; that; and; some; other; thing'
>>> myreplace(' ', '**', 'Words will now be separated by stars.')
'Words**will**now**be**separated**by**stars.'
"""