human
Here's a good function header given the following:
I wrote the below code

    def key_func(item):
        try:
            return getattr(item, attr)
        except AttributeError:
            try:
                return item[attr]
            except TypeError:
                getattr(item, attr)
    return sorted(items, key=key_func)

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

@register.filter
def sort_by(items, attr):