鱼C论坛

 找回密码
 立即注册
查看: 2410|回复: 1

python求解

[复制链接]
发表于 2021-3-14 18:40:36 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

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.
    """
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2021-3-14 18:56:37 | 显示全部楼层
是想要翻译么
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-1-16 06:45

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表