| 123456789101112131415161718192021222324252627282930 |
- #
- # Copyright (c) 2006-2019, RT-Thread Development Team
- #
- # SPDX-License-Identifier: MIT License
- #
- # Change Logs:
- # Date Author Notes
- # 2019-06-13 SummerGift first version
- #
- from ucollections import OrderedDict
- from ucollections import namedtuple
- print("namedtuple example:")
- MyTuple = namedtuple("MyTuple", ("id", "name"))
- t1 = MyTuple(1, "foo")
- t2 = MyTuple(2, "bar")
- print(t1.name)
- print(t2.name)
- assert t2.name == t2[1]
- print("\nOrderedDict example:")
- # To make benefit of ordered keys, OrderedDict should be initialized
- # from sequence of (key, value) pairs.
- d = OrderedDict([("z", 1), ("a", 2)])
- # More items can be added as usual
- d["w"] = 5
- d["b"] = 3
- for k, v in d.items():
- print("%s %s"%(k, v))
|