mageeee 发表于 2021-3-14 18:40:36

python求解

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:
    """Return a new list containing the words from training_text in the
    same order as they appear in training_text.
    """

柿子饼同学 发表于 2021-3-14 18:56:37

是想要翻译么
页: [1]
查看完整版本: python求解