python 字典对根据键值进行的小操作

以下的例子,涉及对字典的键值的判断,以及根据字典键值对键的打印。


x = "googlel"

y = ""
for s in x:
    y = y + s
    usedChar = {}
    for t in y:
        if t not in usedChar:
            usedChar[t] = 1
        else:
            usedChar[t] +=1
    # print(usedChar)
    if 1 in usedChar.values():
        a = list(usedChar.keys())[list(usedChar.values()).index(1)]
        print(a)

猜你喜欢

转载自blog.csdn.net/leokingszx/article/details/79331946