I'm reading up on dataclasses as an alternative to dictionaries with the @dataclass(frozen=True) to make the entries immutable but I don't see how it makes a significant improvement to how the id is retrieved. One thing I would like to improve is maybe how the ids_needed is retrieved and that the user_input is part of the keys of ID_REFERENCE
def do_something(id: str) -> None:
pass
# Default is id i.e. c and e
# as a dict in a config file, easy to reference
ID_REFERENCE: dict[str, str] = {
"a": "a_id",
"b": "b_id",
"c": "id",
"d": "d_id",
"e": "id"
}
# elements are from external service and must be one of the keys in ID_REFERENCE
user_input: list[str] = ["a", "c", "d"]
created_objects: list[str] = ["c", "d", "f", "g"]
# Retrieve objs in ID_REFERENCE and user_input and created_objects
ids_needed: set[str] = set(list(ID_REFERENCE.keys())) & \
set(user_input) & \
set(created_objects)
for obj in ids_needed:
do_something(ID_REFERENCE.get(obj))