str='gbgkkdehh'
b={}
for i in str:
b[i]=str.count(i) #字典b,item写i,value写i在str出现的次数
print(b)
c= [x for x,y in b.items() if y==1] #如果y=1,取b的items,x=item生成列表c
print(c)
print(c[1])
运行结果:
{'g': 2, 'b': 1, 'k': 2, 'd': 1, 'e': 1, 'h': 2}
['b', 'd', 'e']
d