<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _enhance_keys(cls, keys=None, *args, **kwargs):
 """ Enhance the given keys by groups Parameters keys: list of str or None If None, the all formatoptions of the given class are used. Group names from the :attr:`psyplot.plotter.groups` mapping are replaced by the formatoptions Other Parameters %(check_key.parameters.kwargs)s Returns ------- list of str The enhanced list of the formatoptions"""

        all_keys = list(cls._get_formatoptions())
        if isinstance(keys, six.string_types):
            keys = [keys]
        else:
            keys = list(keys or sorted(all_keys))
        fmto_groups = defaultdict(list)
        for key in all_keys:
            fmto_groups[getattr(cls, key).group].append(key)
        new_i = 0
        for i, key in enumerate(keys[:]):

            if key in fmto_groups:
                del keys[new_i]
                for key2 in fmto_groups[key]:
                    if key2 not in keys:
                        keys.insert(new_i, key2)
                        new_i += 1
            else:
                valid, similar, message = check_key(
                    key, all_keys, False, 'formatoption keyword', *args,
                    **kwargs)
                if not valid:
                    keys.remove(key)
                    new_i -= 1
                    warn(message)
            new_i += 1
        return keys