1. 程式人生 > >python 字典對根據鍵值進行的小操作

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)