Python 类似字典的数据结构

Python data structure like dict

在网上找到了一些使用变量explored的代码。 这个变量像字典一样实现:explored = {rootId},但是它没有键值关联,而且这个变量使用函数.add(elem)而dict没有这个函数。 例如。 explored.add(elem).

那是哪个数据结构? (我正在使用 python 3.6.3)

这是 set 数据结构。 这是官方文档中的 link:https://docs.python.org/3/tutorial/datastructures.html#sets

这是一个使用你提到的方法的 set. There are also online examples

下次你想知道的时候,我建议你只打印类型,就像这样:

print(type(explored));

可能是一个集合,它有一个方法"add",但是你可以简单地打印类型,比如:

print(type(explored))