Crag的博客

自学编程

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))
阅读更多
个人分类: jeapedu
上一篇jeapedu 131 集合的習題4方法二
下一篇jeapedu 133 集合的習題6
想对作者说点什么? 我来说一句

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

关闭
关闭