Python:创建文档抽象数据类型并添加字典变量 由 met发布于 2020-05-18 13:44:03 我试图在Python中创建文档抽象数据类型,并向其中添加一个字典变量,以跟踪文档中唯一单词及其出现的频率。我在正确的轨道上吗?我是抽象数据类型的新手,我不确定自己是否做对了。 class Document: dict = {}
You need to use Abstract Base Classes for defining abstract classes in Python:
Another problem in your code is that the way you defined your
dict
attribute makes it mutable across all instances of Document. For example:除非这是理想的行为(不是因为每个文档中的字数都不同),否则您需要以下内容:
这条路,