Python中一些非常好用的函数

1,Counter 函数

from collections import Counter
a=Counter('jfdhuhweurhfsjknvfiauwrfhawfjawufh')
print(a)
Counter({'f': 6, 'h': 5, 'u': 4, 'w': 4, 'j': 3, 'a': 3, 'r': 2, 'd': 1, 'e': 1, 's': 1, 'k': 1, 'n': 1, 'v': 1, 'i': 1})
dict_values([3, 6, 1, 5, 4, 4, 1, 2, 1, 1, 1, 1, 1, 3])
dict_keys(['j', 'f', 'd', 'h', 'u', 'w', 'e', 'r', 's', 'k', 'n', 'v', 'i', 'a'])

可以用于生成一个字典对象,字典的操作函数同样适用

猜你喜欢

转载自blog.csdn.net/weixin_39995352/article/details/84257273