Python:怎么使用Counter对象most_common()方法

2024-10-13 03:58:41

1、首先在PyCharm软件中,打开一个Python项目。

Python:怎么使用Counter对象most_common()方法

3、在python文件编辑区中,输入:“from collections import Counter”,导入 collections 模块中的 Counter 类。

Python:怎么使用Counter对象most_common()方法

5、接着输入:“x = c.most_common(3)”,点击Enter键。

Python:怎么使用Counter对象most_common()方法

7、在编辑区域点击鼠标右键,在弹出菜单中选择“运行”选项。

Python:怎么使用Counter对象most_common()方法
猜你喜欢