ucollections.py 688 B

1234567891011121314151617181920212223242526272829
  1. /*
  2. * Copyright (c) 2006-2019, RT-Thread Development Team
  3. *
  4. * SPDX-License-Identifier: MIT License
  5. *
  6. * Change Logs:
  7. * Date Author Notes
  8. * 2019-06-13 SummerGift first version
  9. */
  10. from ucollections import namedtuple
  11. MyTuple = namedtuple("MyTuple", ("id", "name"))
  12. t1 = MyTuple(1, "foo")
  13. t2 = MyTuple(2, "bar")
  14. print(t1.name)
  15. assert t2.name == t2[1]
  16. ucollections.OrderedDict(...)
  17. from ucollections import OrderedDict
  18. # To make benefit of ordered keys, OrderedDict should be initialized
  19. # from sequence of (key, value) pairs.
  20. d = OrderedDict([("z", 1), ("a", 2)])
  21. # More items can be added as usual
  22. d["w"] = 5
  23. d["b"] = 3
  24. for k, v in d.items():
  25. print(k, v)