Python Forum
Deleting value from dictionary.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Deleting value from dictionary.
#4
(May-18-2018, 01:38 AM)dbdb12 Wrote: All keys and values are strings in this case.
(May-18-2018, 02:00 AM)dbdb12 Wrote: So like:
dictionary = {"hello":["hey", "dinosaur", "dragon"], "fire:["volcano", "explosion", "boom"]}
well, note that your statement and your example contradict to each other. In your example the key is a string, the value is a list. And that list has number of elements that are strings.
anyway, something like this should work:
dictionary = {"hello":["hey", "dinosaur", "dragon"], "fire":["volcano", "explosion", "boom"]}
new_dict = dict()
for key, value in dictionary.items():
    new_dict[key] = [s for s in value if len(s)>5]
print(new_dict)
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Messages In This Thread
Deleting value from dictionary. - by dbdb12 - May-18-2018, 01:38 AM
RE: Deleting value from dictionary. - by Larz60+ - May-18-2018, 01:48 AM
RE: Deleting value from dictionary. - by dbdb12 - May-18-2018, 02:00 AM
RE: Deleting value from dictionary. - by buran - May-18-2018, 07:07 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  deleting item from dictionary Skaperen 6 3,142 Feb-20-2019, 01:18 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020