code: def extract_attr_for_match(items, **kwargs):
    query_arg = None
    for arg, value in kwargs.items():
      if value == -1:
        assert query_arg is None, "Only single query arg (-1 valued) is allowed"
        query_arg = arg
    result = []
    filterset = set(kwargs.keys())
    for item in items:
      match = True
      assert filterset.issubset(
        item.keys()), "Filter set contained %s which was not in record %s" % (
        filterset.difference(item.keys()),
        item)
      for arg in item:
        if arg == query_arg:
          continue
        if arg in kwargs:
          if item[arg] != kwargs[arg]:
            match = False
            break
      if match:
        result.append(item[query_arg])
    assert len(result) <= 1, "%d values matched %s, only allow 1" % (
      len(result), kwargs)
    if result:
      return result[0]
    return None