0

That's really just my question. All I can find online is how to remove a key-value pair, but not how to remove a specific value from a key if the values of that key are a list. ex: a key Emotions values are ['neutral', 'happy'] and I only want to remove 'happy'. dictionary[Emotions].remove('happy') isn't working at all.

3
  • 1
    I suggest you break this down into simpler pieces. First, you need to figure out how to remove an element from a list. Don't worry about the dictionary part. When you google, "python remove element from list", one of the hits is this question on Stack Overflow. Start with that and see if it helps. Commented May 28, 2021 at 20:53
  • 4
    Please provide the exact code that isn't working for you, because on my computer this works fine. Commented May 28, 2021 at 20:54
  • If you need additional help, please post a minimal reproducible example that shows exaclty what you tried. Then explain exactly what happens when you run your code and what you want it to do differently. BE SPECIFIC. The more detail you provide, the better we can help you. Just saying it "isn't working" doesn't give us enough information. Commented May 28, 2021 at 20:55

1 Answer 1

3

I am not sure where the encountered problems are. You may like to compare your codes with the correctly executed codes below:

Emotions = 'emotions'
dictionary = {Emotions: ['neutral', 'happy']}
print(dictionary)
dictionary[Emotions].remove('happy')
print(dictionary)

Output

{'emotions': ['neutral', 'happy']}
{'emotions': ['neutral']}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.