The next step is to search the geocaching points by their attributes. For example, we may want to filter the points by the author of the geocache, by the level of difficulty to find the geocache, and so on.
We will borrow the techniques used in the methods that allowed us to get a GeoObject by its name property and the method that filtered by a polygon. The difference here is that we must allow the attribute that we want to filter by to be passed as a parameter, and we want to have the capability to combine multiple fields.
Let's start adding a simple filter method in the
BaseGeoCollection
class:#... def filter(self, attribute, value): """Filters the collection by an attribute. :param attribute: The name of the attribute to filter by. :param value: The filtering value. """ result = [] for item in self.data: if item.get_attribute(attribute) == value: result.append(item) ...