Drop zero counts
EasyYou're cleaning a count dict: drop every key whose value is
0. The draft deletes as it walks.Given a dictionary of counts, write a function that returns a dictionary with only the keys whose count is not
0.For example, given
{"dog": 2, "cat": 0, "bird": 1}
Your function should return
{"dog": 2, "bird": 1}
The order of keys doesn't matter.
The starter deletes inside
for word in counts. Run it first.Try it first
Solution
10 Essential DSA in the AI era Coding Interview Problems
Master DSA in the AI era by trying the coding challenges below.
- 1.Count occurrencesEasy
- 2.Fix the default listEasy
- 3.Move zeroesEasy
- 4.Is subsequenceEasy
- 5.First unique characterEasy
- 6.Group anagramsMedium
- 7.Climb stairsEasy
- 8.Find the targetEasy
- 9.Drop zero countsEasy
- 10.Same valueEasy
