<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def prefer_master(nodes: List[DiscoveredNode]) -> Optional[DiscoveredNode]: """ Select the master if available, otherwise fall back to a replica. """

    return max(nodes, key=attrgetter("state"))