所以这里的语法有点混乱,但是实际发生的是
c.items()
是包含单词及其计数的元组。
更明确的写作方式是:
vocab = [x for (x, count) in c.items() if x>=2]
但也可以这样做:
vocab = [x[0] for x in c.items() if x[1]>=2]
哪里
x
是元组。
也有助于了解
c
实际上看起来像。如果打印c,您会看到:
>>> print c
Counter({'lie': 3, 'is': 2, 'and': 1, 'a': 1, 'There': 1, 'only': 1, 'passion': 1, 'piece': 1})
和
C项()
>>> print c.items()
[('and', 1), ('a', 1), ('lie', 3), ('is', 2), ('There', 1), ('only', 1), ('passion', 1), ('piece', 1)]