Take a look at ```qiime.util.MetadataMap```. This class likely provides much of the functionality you need here, e.g. checking the number of classes in a column.