查看micropython标准库
这个模块实现了高级集合和容器类型,可以容纳各种对象。
Classes
ucollections.namedtuple(name, fields)
from ucollections import namedtuple
MyTuple = namedtuple("MyTuple", ("id", "name"))
t1 = MyTuple(1, "foo")
t2 = MyTuple(2, "bar")
print(t1.name)
assert t2.name == t2[1]
ucollections.OrderedDict(...)
from ucollections import OrderedDict
# 为了利用ordered keys,需要初始化OrderedDict
# from sequence of (key, value) pairs.
d = OrderedDict([("z", 1), ("a", 2)])
# 可以添加更多条目
d["w"] = 5
d["b"] = 3
for k, v in d.items():
print(k, v)
输出结果:
z 1
a 2
w 5
b 3