def METHOD_NAME(collection, k, v):
    result = []
    for d in collection:
        if hasattr(d, k):
            value = getattr(d, k)
        else:
            value = d.get(k)
        if (v is None and value is None) or value == v:
            result.append(d)
    if not result:
        return None
    assert len(result) == 1
    return result[0]