# 注意Counter() 输入的是字符串 返回的是用于计算字符串中字符出现的接口
word_counts.most_common() 输入整数时C 返回的是排名前C个的数据 不输入是按照出现次数对所有数据排序
word_counts.most_common() 返回值的类型是list[] 第一个参数:字符 第二个参数是:字符出现的次数
[x[0] for x in word_counts.most_common()]的作用就是将word_counts.most_common() 返回值的第一个参数x[0]赋值给 vocabulary_inv
from collections import Counter
str_var = '不管你爱不爱深度学习 反正我爱'
word_counts = Counter(str_var)
#每次都把都把word_counts.most_common()中的汉字 返回给vocabulary_inv
vocabulary_inv = [x[0] for x in word_counts.most_common()]
print("vocabulary_inv和类型",vocabulary_inv, type(vocabulary_inv))
my_vocabulary_inv = []
for x in word_counts.most_common():
my_vocabulary_inv.append(x[0])
print("my_vocabulary_inv",my_vocabulary_inv)
vocabulary_inv_three = [x[0] for x in word_counts.most_common(3)]
print("vocabulary_inv_three", vocabulary_inv_three)