fork download
  1. direction = ["東", "西", "北", "北", "南", "東", "北"]
  2.  
  3. import collections
  4.  
  5. one_key_Counts = collections.Counter(direction)
  6. print(one_key_Counts)
  7. print(one_key_Counts["北"])
  8.  
  9. tow_key_Counts = collections.Counter(zip(direction[:-2],direction[1:]))
  10. print(tow_key_Counts)
  11. print(tow_key_Counts[("西", "北")])
  12.  
Success #stdin #stdout 0.01s 27712KB
stdin
Standard input is empty
stdout
Counter({'北': 3, '東': 2, '南': 1, '西': 1})
3
Counter({('北', '南'): 1, ('北', '北'): 1, ('南', '東'): 1, ('東', '西'): 1, ('西', '北'): 1})
1