human
I wrote the below code

    affinity_str = affinity_str.strip()
    if (not affinity_str):
        return (lambda x: 0)
    priority_matchers = []
    pieces = [s.strip() for s in affinity_str.split(',')]
    for piece in pieces:
        match = re.match('r(\\d+)(?:z(\\d+))?=(\\d+)$', piece)
        if match:
            (region, zone, priority) = match.groups()
            region = int(region)
            priority = int(priority)
            zone = (int(zone) if zone else None)
            matcher = {'region': region, 'priority': priority}
            if (zone is not None):
                matcher['zone'] = zone
            priority_matchers.append(matcher)
        else:
            raise ValueError(('Invalid    affinity    value:    %r' % affinity_str))
    priority_matchers.sort(key=operator.itemgetter('priority'))
    def keyfn(ring_node):
        for matcher in priority_matchers:
            if ((matcher['region'] == ring_node['region']) and (('zone' not in matcher) or (matcher['zone'] == ring_node['zone']))):
                return matcher['priority']
        return 4294967296
    return keyfn

What's a good function header?

=====
Here's a good function header?
assistant
#Here's a good function header.

def affinity_key_function(affinity_str):