Simple Database Query Processor
Function Name: processQuery
Description
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.
Requirements
- The function must be named 'processQuery'.
- The function must take two parameters: a list of dictionaries representing the dataset and a query string.
- Determine whether each row matches the query condition and return a filtered list of dictionaries.
- Assume all dictionary values and query values are strings.
- If a query is malformed or refers to a column that does not exist, return an empty list.
- Do not use any external libraries or modules.
Examples
Given the following list of dictionaries:[{'id': '1', 'name': 'Alice'}, {'id': '2', 'name': 'Bob'}]And the query string:'name == Bob'The function should return:[{'id': '2', 'name': 'Bob'}]
Links
Sum Of Two Linked Lists
Tue Oct 01 2024
Write a function 'sumOfLinkedLists' that takes two arguments representing the heads of two non-empty linked lists, each of which contains non-negative integers. The digits are stored in reverse order, with each of their nodes containing a single digit. Add the two numbers and return the sum as a linked list in the same reversed format.The function should create a new linked list that represents the sum of the numbers, with nodes containing single digits and the linked list still reversed.You can assume the two linked lists do not contain any leading zeros, except for the number 0 itself.
Flatten Nested Dictionary
Thu Oct 03 2024
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.