from typing import Any, Union def format_for_dataloader( items: list[dict[str, Any]], keys: list[Any], lookup_key: str, ) -> list[Union[dict[str, Any] | None]]: """Transforms a list of items to be a dataloader-formatted list of items. Items will be ordered by the keys provided. Where no item is found for the key, None is used for the item. """ items_dict = {str(item[lookup_key]): item for item in items} return [items_dict.get(str(key), None) for key in keys]