思路:列表中元素,做字典的key值,
字典的key對應的values是出現的次數
def pin(t):
d=dict()###空字典
lenth=len(t)
for i in t:
if i not in d:
d[i]=1
else:
d[i]+=1
for line in d: ##算出key在列表中出現的頻率
val=d[line]/lenth
print(line,'在列表中出現的評率為',(round(val,2))) ##round 是val是小數位2位
return d
t=[1,2,3,2,2,'h','a','hello','hello']
print(pin(t))