Explorar el Código

【添加】ucollections 例程

SummerGift hace 6 años
padre
commit
06cc9d05a5
Se han modificado 1 ficheros con 5 adiciones y 4 borrados
  1. 5 4
      examples/basic/ucollections.py

+ 5 - 4
examples/basic/ucollections.py

@@ -8,17 +8,18 @@
 # 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]
-ucollections.OrderedDict(...)
-
-from ucollections import OrderedDict
 
+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)])
@@ -26,4 +27,4 @@ d = OrderedDict([("z", 1), ("a", 2)])
 d["w"] = 5
 d["b"] = 3
 for k, v in d.items():
-    print(k, v)
+    print("%s %s"%(k, v))