code: def to_list_of_dictionaries(df: DataFrame) -> list[dict[str, Any]]:
      """Convert a Spark DataFrame to a list of dictionaries.
  
      :param df: The Spark DataFrame to convert.
      :type df: :py:class:`pyspark.sql.DataFrame`
      :return: A list of dictionaries representing the rows in the DataFrame.
      :rtype: List[Dict[str, Any]]
      """
      return list(map(lambda r: r.asDict(), df.collect()))
  
file_path: quinn/quinn/dataframe_helpers.py
imports: from __future__ import annotations
  from typing import TYPE_CHECKING
  from typing import Any
  from pyspark.sql.types import StructField, StructType
label_desc: Use image node_id 3 for calling a global function with example usage: to_list_of_dictionaries(df) and returns: list