When investigating a new dataset, it is very helpful to have a way to quickly check which values a column contains. In this recipe, we will use different approaches using both the GUI and the Python console to list the unique values of POI classes in our sample POI dataset.
If you are simply looking for a solution based on the GUI, the List unique values tool is available both in Vector | Analysis Tools as well as in the Processing Toolbox menu. You can use either one of these to get a list of the unique values in a column. Having this tool available in the Processing Toolbox menu makes it possible to include it in processing models and, thus, automate the process. The following steps to list unique values use the Processing Toolbox menu:
poi_names_wake layer as Input layer and the class attribute as Target field.If you want to further customize this task, for example, by counting how often the values appear in this dataset, it's time to fire up Python console:
import processing
layer = iface.activeLayer()
classes = {}
features = processing.features(layer)
for f in features:
attrs = f.attributes()
class_value = f['class']
if class_value in classes:
classes[class_value] += 1
else:
classes[class_value] = 1
print classesThe following screenshot shows what the screen looks like:

In the first line, we use import processing because it offers a very handy and convenient function, processing.features(), to access layer features, which we use in line 7. It is worth noting that, if there is a selection, processing.features() will only return an iterator of the selected features.
In line 3, we get the currently active layer object. Line 5 creates the empty dictionary object, which we will fill with the unique values and corresponding counts.
The for loop, starting on line 5, loops through all features of the layer. For each feature, we get the value in the classification field (line 7). You can change the column name to analyze other columns. Then, we only need to check whether this value is already present in the classes dictionary (line 8) or whether we have to add it (line 11).