'Build the export lists.'

def __build_export(self, stats):

    export_names = []
    export_values = []
    if isinstance(stats, dict):
        if (('key' in iterkeys(stats)) and (stats['key'] in iterkeys(stats))):
            pre_key = '{}.'.format(stats[stats['key']])
        else:
            pre_key = ''
        for (key, value) in iteritems(stats):
            if isinstance(value, list):
                try:
                    value = value[0]
                except IndexError:
                    value = ''
            if isinstance(value, dict):
                (item_names, item_values) = self.__build_export(value)
                item_names = [((pre_key + key.lower()) + str(i)) for i in item_names]
                export_names += item_names
                export_values += item_values
            else:
                export_names.append((pre_key + key.lower()))
                export_values.append(value)
    elif isinstance(stats, list):
        for item in stats:
            (item_names, item_values) = self.__build_export(item)
            export_names += item_names
            export_values += item_values
    return (export_names, export_values)
