fromCollectionsImportNamedtuple,deque,defaultdict,ordereddict,counterImportQueue#can name tuples, namedtuplePoint = Namedtuple (' Point',['x','y']) P= Point ()Print(P.X,P.Y)#Output Results: 1 2#deque Dual-ended queueA = Deque (['a','b','C','D']) A.appendleft ('x')Print(a)#Output Result: deque ([' X ', ' A ', ' B ', ' C ', ' d '])A.append ('y')Print(a)#output: Deque ([' X ', ' A ', ' B ', ' C ', ' d ', ' Y '])b =A.pop ()Print(b)#output Result: Yc =A.popleft ()Print(c)#output Result: xA.insert (2,3)#not recommended for this .Print(a)#output: deque ([' A ', ' B ', 3, ' C ', ' d '])#Queue FIFO FirstQ =queue. Queue () Q.put (10) Q.put (5) Q.put (4) Q.put (3) Q.put (2)Print(q)Print(Q.get ())#TenPrint(Q.get ())#5Print(Q.qsize ())#defaultdictDIC = Defaultdict (Lambda:'N /A') dic['K1'] ='ABC'Print(dic['K2'])#The output is n/a . The default value is returned when key does not exist. #Ordereddict ordered dictionaryD = ordereddict ([('a', 1), ('b', 2), ('C', 3)])Print(List (D.keys ()))#Counter The purpose of this class is used to track the number of occurrences of a value, which is an unordered container, stored as a dictionary#where the element is a key, its count as value. CC = Counter ('ABCDADFKDFJ')Print(CC)#output: Counter ({' d ': 3, ' F ': 2, ' a ': 2, ' C ': 1, ' K ': 1, ' J ': 1, ' B ': 1})#detailed description of the address: http://wwww.cnblogs.com/Eva-J/articles/7291842.html
Python----Collections Module