简体   繁体   中英

Python - argument of type 'float' is not iterable

I have this code in Python. I want to increment the value (float) of score for each key in dictionary... But i have always the error "argument of type 'float' is not iterable".

Anyone can help me? Thanks. :)

dictVocabulary is like this:

'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}

And the dictionary "emo" is like this:

{'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

Here is a function for incrementing those dictionarys

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM