""" Generic utility functions for the app. """ from typing import Any def lowercase_keys(data: dict | list) -> Any: """Recursively lowercases the keys of a dictionary or list of dictionaries. Args: data (dict or list): The input data, which can be a dictionary or a list of dictionaries. If it's a list, all dictionaries in the list will have their keys lowercased. If it's a dictionary, its keys will be lowercased. Returns: dict or list: The input data with all keys lowercased. Raises: TypeError: If the input data is neither a dictionary nor a list of dictionaries. """ if isinstance(data, list): return [lowercase_keys(item) for item in data] elif isinstance(data, dict): return {k.lower(): lowercase_keys(v) for k, v in data.items()} # If the data is neither a dictionary nor a list, return it as is, # to stop recursion. return data