|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
We will represent the words in the original story (the training text) as a list of strings. You'll need to read the words in the training text file and create that list. This string method will help:
>>> help(str.split)
Help on method_descriptor:
split(...)
S.split(sep=None, maxsplit=-1) -> list of strings
Return a list of the tokens in S, using sep as the
delimiter string. If maxsplit is given, at most maxsplit
splits are done. If sep is not specified or is None, any
whitespace string is a separator and empty strings are
removed from the result.
Read the last sentence of that description carefully.
If a variable training_text represents a file open for reading, then training_text.read() returns a string containing the entire contents of the file. You can use the str method split to make your list.
Complete the function below according to its docstring description.
from typing import TextIO, List
def get_words(training_text: TextIO) -> List[str]:
"""Return a new list containing the words from training_text in the
same order as they appear in training_text.
""" |
|