From the course: Programming Foundations: Data Structures (2023)

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Solution: Drop empty items

Solution: Drop empty items

- [Instructor] It's important to clean your data if some of it is invalid or missing. Let's clean a given dictionary by removing the key value pairs with empty or none values. First we'll create a dictionary to hold our updated preferences, then we'll iterate through the passed in dictionary and check whether a given key has a none value. If the value is not none, then we should add it to our dictionary. After iterating through the original dictionary, the updated preferences should have our clean data. Let's return it from the function, and we'll run it. No more none values. They're deleted with our new dictionary. No more none values with our new dictionary. The time complexity of this algorithm is O of N because we iterate through the input one time. This means as the input grows in size, so will the time that it takes to run the algorithm. That's linear time complexity. We can simplify this implementation by…

Contents