def find_data_in_nested_structure(
    data: Sequence[Any] | dict[str, Any], key: str
) -> list[Any]:
  """Recursively finds all instances of a given key in nested dictionaries/lists."""
  results = []
  if isinstance(data, dict):
    for k, v in data.items():
      if k == key:
        results.append(v)
      results.extend(find_data_in_nested_structure(v, key))
  elif isinstance(data, list):
    for item in data:
      results.extend(find_data_in_nested_structure(item, key))
  return results
Recursively finds all instances of a given key in nested dictionaries/lists.
concordia/utils/helper_functions.py