该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
def check_syllables(poem_lines, pattern, word_to_phonemes):
r""" (list of str, poetry pattern, pronunciation dictionary) -> list of str
Precondition: len(poem_lines) == len(pattern[0])
Return a list of lines from poem_lines that do not have the right number of
syllables for the poetry pattern according to the pronunciation dictionary.
If all lines have the right number of syllables, return the empty list.
>>> poem_lines = ['The first line leads off,', 'With a gap before the next.', 'Then the poem ends.']
>>> pattern = ([5, 5, 4], ['*', '*', '*'])
>>> word_to_phonemes = {'NEXT': ['N', 'EH1', 'K', 'S', 'T'],
... 'GAP': ['G', 'AE1', 'P'],
... 'BEFORE': ['B', 'IH0', 'F', 'AO1', 'R'],
... 'LEADS': ['L', 'IY1', 'D', 'Z'],
... 'WITH': ['W', 'IH1', 'DH'],
... 'LINE': ['L', 'AY1', 'N'],
... 'THEN': ['DH', 'EH1', 'N'],
... 'THE': ['DH', 'AH0'],
... 'A': ['AH0'],
... 'FIRST': ['F', 'ER1', 'S', 'T'],
... 'ENDS': ['EH1', 'N', 'D', 'Z'],
... 'POEM': ['P', 'OW1', 'AH0', 'M'],
... 'OFF': ['AO1', 'F']}
>>> check_syllables(poem_lines, pattern, word_to_phonemes)
['With a gap before the next.', 'Then the poem ends.']
>>> poem_lines = ['The first line leads off,']
>>> check_syllables(poem_lines, ([0], ['*']), word_to_phonemes)
[]
"""
万能的贴吧,有人可以告诉我这个到底怎么做啊!