python中defaultdict类

回宿舍前翻翻Codeforces的时候发现了一个有趣的代码..其实是我没这么用过 :D

这是一份417B的代码

 1 import sys

 2 from collections import defaultdict

 3 

 4 n = int(sys.stdin.readline())

 5 d = defaultdict(lambda:-1)

 6 for i in range(0, n):

 7   x, k = map(int, sys.stdin.readline().split())

 8   z = d[k]

 9   if x == z + 1:

10     d[k] = x

11   elif x > z + 1:

12     print('NO')

13     sys.exit(0)

14 

15 print('YES')

于是搜了下defaultdict,一个类.不过我是还没理解,记录下来以后学习一下.

这里又一篇相关的文章:点我

你可能感兴趣的:(python)