shaoheshaohe 发表于 2020-12-28 17:14:23

python--统计列表中不同元素的数量

代码如下;

list=
print(list)
set1=set(list)
print(set1)
print(len(set1))#len(set1)即为列表中不同元素的数量
得到结果:

{1, 2, 3}
3

原理就是set集合中不允许重复元素出现。

shaoheshaohe 发表于 2020-12-28 17:14:34

https://blog.csdn.net/wenqiwenqi123/article/details/78116544/

shaoheshaohe 发表于 2020-12-28 17:14:56

https://blog.csdn.net/wenqiwenqi123/article/details/78116544/
页: [1]
查看完整版本: python--统计列表中不同元素的数量