Accessing properties like attributes

I’ve got a code snippet that I’m using many times for various rooms. I want to set the schedule name once as a string to be used throughout the template for that room. It’s fine for states() and state_attr(), but as you can see below, I still need to include the name of the schedule separately to get access to the 'last_changed' property.

    {% set schedule_name="schedule.schedule_bathroom"%}
    {% set last=states.schedule.schedule_bathroom.last_changed %}
    {% set next=state_attr(schedule_name,'next_event') %}
    {% set schedule=states(schedule_name) %}

I understand that the below doesn’t work because 'last_changed' is a property, not an attribute, but I would like something along the lines of how you might imagine this to work

    {% set schedule_name="schedule.schedule_bathroom"%}
    {% set last=state_attr(schedule_name,'last_changed') %}
    {% set next=state_attr(schedule_name,'next_event') %}
    {% set schedule=states(schedule_name) %}

Looking for any recommendations?

Many thanks!

{% set last =  states[schedule_name].last_changed %}

I knew it would have square brackets in there somewhere. Perfect thank you!