python list set dict的简单应用示例

list.count(x):返回指定元素x在列表中出现的次数

set(list):将list类型变量转换为set类型,去除重复值

dick:保存键值对

x=[1,2,2,3,3]
s1=set(x)  #不含重复值的集合
d1={}
for i in s1:
    d1[i]=x.count(i)  #count函数
print(d1)  #{1: 1, 2: 2, 3: 2}
原文地址:https://www.cnblogs.com/imhuanxi/p/10994781.html