python 计数器Counter

 1 from collections import Counter
 2 colours=(
 3     ('Yasoob','Yellow',1), 
 4     ('Ali','Blue',2), 
 5     ('Arham','Green',3), 
 6     ('Ali','Black',4), 
 7     ('Yasoob','Red',5), 
 8     ('Ahmed','Silver',6),
 9     ('Ahmed','Red',7),
10 )
11 
12 favs = Counter((name,colour) for name, colour,value in colours)
13 unions=Counter(name for name, colour,value in colours)
14 print(favs)
15 print(unions)

 

posted on 2018-12-31 11:13  hailuo  阅读(346)  评论(0编辑  收藏  举报