zipline86
zipline86

Reputation: 661

update dictionary values with for loop

I have a list of dictionaries and would like to iterate through it using a for loop and update one of the keys values into categorical data. I made a for loop but when I look at the list it shows the original data without any changes. How can I get this to work?

# Change quality into categorical data

for wine in wines:
    if wine["quality"] <= 4:
        wine["quality"] == "Bad"
    elif wine["quality"] <= 8:
        wine["quality"] == "Average"
    else:
        wine["quality"] == "Excellent"

Upvotes: 0

Views: 93

Answers (1)

FredMan
FredMan

Reputation: 829

Instead of doing assignment you have done an equality comparison.

replace == with =

Upvotes: 1

Related Questions