jeapedu 132 集合的習題5

链接: https://pan.baidu.com/s/1SzWqGtyiMUH1lsnrQIiHgg 密码: cwx6

# 6 find same value's key
d1 = dict(a = 12, b = 13, c = 12, d = 15, e = 19)
print(d1)
dk = d1.keys()
dv = list(d1.values())
print(dk, dv)
sdv = set(dv)
print(sdv)
if len(sdv) == len(dv):
    print('no repeat values')
else:
    print('has repeat valuesl')
ldv = list(sdv)
print(ldv)
rep = list()
for x in ldv:
    if list(dv).count(x) > 1:
        #print(x)
        rep.append(x)
print('rep', rep)
for x in rep:
    for y in d1:
        if d1[y] == x:
            print(x, y)
print('dv', dv)
print('ldv', ldv)
for x in dv:
    if x in ldv and dv.count(x) > 1:
        dv.remove(x)
print('left', set(dv))

dv = list(d1.values())
print('dv', dv)
i = 0
while i < len(dv):
    if dv.count(dv[i]) == 1:
        dv.remove(dv[i])
        i -= 1
    i += 1
print('1 dv', dv) 
print(set(dv))

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试

关闭