'Filter current recordset only keeping the most suitable view per distinct key'

def filter_duplicate(self):

    filtered = self.env['ir.ui.view']
    for (dummy, group) in groupby(self, key=(lambda record: record.key)):
        filtered += sorted(group, key=(lambda record: record._sort_suitability_key()))[0]
    return filtered
