Flatten Nested Dictionary
Function Name: flatten_dictionary
Description
In this challenge, you are to write a function named 'flatten_dictionary' that takes a dictionary with nested dictionaries as values and returns a new dictionary with flattened keys.
The keys in the output dictionary should be a combination of the nested keys, separated by a period ('.').
If an inner dictionary has an empty key, it should just be appended without the preceding dot.
Values from nested dictionaries are to be included in the result as is, without further nesting.
The input dictionary will only contain other dictionaries or scalar values (e.g., strings, integers).
Requirements
- The function should take one parameter: a dictionary to flatten.
- The function should return a new dictionary with no nested dictionaries, where the keys are the 'paths' from the original nested structure.
- Nested dictionaries should be flattened recursively.
- Empty keys in nested dictionaries should not lead to leading dots in the keys of the flattened dictionary.
- Handling of scalar values (non-dictionaries) within the nested dictionaries should not change.
Examples
Given the dictionary {'a': 1, 'b': {'c': 2, 'd': {'': 3, 'e': 4}}}, the function should return {'a': 1, 'b.c': 2, 'b.d': 3, 'b.d.e': 4}.Given the dictionary {'nested': {'inner': {'': 'value'}}}, the function should return {'nested.inner': 'value'}.
Links
Token Bucket Rate Limiter
Fri Dec 27 2024
Write a function 'rateLimiter' that simulates a token bucket rate limiter. The token bucket algorithm is used to control the amount of data that is transferred, which can help prevent denial of service attacks or network congestion. Your rate limiter must be stateful and should handle incrementing tokens in the bucket at a steady rate as well as decrementing them when a request is made.
Matrix Spiral Copy
Sun Dec 29 2024
Write a function 'spiralCopy' that takes a 2D array (matrix) as an input and returns a list (or array) of elements in the order they are visited in a spiral traversal, starting from the top-left corner and proceeding inwards in a clockwise direction.