簡體   English   中英

Python - 'float' 類型的參數不可迭代

[英]Python - argument of type 'float' is not iterable

我在 Python 中有這個代碼。 我想增加字典中每個鍵的得分值(浮點數)......但我總是出現錯誤“'float'類型的參數不可迭代”。

任何人都可以幫助我嗎? 謝謝。 :)

dictVocabulary 是這樣的:

'Affect and Emotion': {'affect': 1.0, 'emotion': 1.0, 'fearless':0.7, 'scarier':0.8}, 
'Comfort': {'comfort': 1.0, 'problem':0.8,'bad':0.8,'mistake':0.8}

字典“emo”是這樣的:

{'Anticipation': '0.2222222222222222', 'Positive feelings': '0.3333333333333333'}
for d in dictVocabulary.items():
        #print(voc)
        concept = d[0]
        pals = d[1]
        score=0.00
        for pal, prob in pals.items():
            #print(pal, prob)
            for c,v in emo.items(): 
                if (c in pal):
                    score = v
                    if concept not in scoreDict.keys():
                        scoreDict[concept] = score
                    elif score not in scoreDict[concept]:
                        scoreDict[concept] += score

這是用於增加這些字典的 function

dictVocabulary = {'Affect and Emotion': {'affect': 1.0, 'emotion': 1.0, 'fearless':0.7, 'scarier':0.8}, 'Comfort': {'comfort': 1.0, 'problem':0.8,'bad':0.8,'mistake':0.8}}
emo = {'Anticipation': 0.2222222222222222, 'Positive feelings': 0.3333333333333333}



def increment(points: float):
    # incrementing dictVocabulary
    for types in dictVocabulary:
        for items in dictVocabulary[types]:
            dictVocabulary[types][items] += points
    # incrementing emo
    for items in emo:
        emo[items] += points

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM