Manafall Daily Quest

Flatten Nested Dictionary

Function Name: flattenDictionary

Description

Write a function 'flattenDictionary' that takes as input a dictionary with nested dictionaries and returns a flat version of it (a dictionary with no nested dictionaries).

Keys in the flattened dictionary should be composed of the keys from the original nested dictionaries, joined with a '.' (period).

If a certain key has an empty dictionary as its value, then just represent the key with an empty object in the flattened dictionary.

The function should handle an arbitrary level of nesting.

Requirements

  • The function should take exactly one parameter: the nested dictionary
  • The function should return a new dictionary with no nested dictionaries
  • Nested keys should be concatenated with a '.' to create the new key
  • Empty dictionaries should result in keys with no value
  • The original dictionary should not be modified
  • Keys should maintain the order they appear in the original dictionary
  • You should not use any third-party libraries

Examples

Given the nested dictionary {'a': 1, 'b': {'c': 2, 'd': {'e': 3}}, 'f': {'g': {}}}, the function should return {'a': 1, 'b.c': 2, 'b.d.e': 3, 'f.g': {}}Given the nested dictionary {'foo': {'bar': {'baz': 123}}}, the function should return {'foo.bar.baz': 123}

Links

https://en.wikipedia.org/wiki/Recursion_(computer_science)https://docs.python.org/3/tutorial/datastructures.html#dictionaries

Simple Database Query Processor

Wed Oct 02 2024

Write a function that simulates a simple database query processor. The function should accept two parameters: a list of dictionaries representing 'rows' in a database table, and a query string representing a simple filtering condition. Each dictionary in the list corresponds to a database row, where the key-value pairs of the dictionary correspond to column names and cell data, respectively.The query string will be a simple conditional statement in the format 'column_name == value', where 'column_name' is a key in the dictionaries and 'value' is the value to match. The function should return a list of dictionaries where the condition is true.For simplicity, assume that all column values are strings and that the queries use '==' for equality checks only. Handle the case where the query string is malformed or columns do not exist—return an empty list in these situations.

Prev Quest

Balanced Parentheses

Fri Oct 04 2024

Write a function called 'checkBalancedParentheses' that takes a string containing only parentheses (i.e., '(', ')', '[', ']', '{', '}') and determines if the parentheses in the string are balanced. A string has balanced parentheses if each type of parenthesis is closed in the correct order. You may ignore any characters other than the six valid parentheses characters.

Next Quest