<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def generate(self, gender=None, part=None, snake_case=False, weighted=False):
 """Generate a Queb name. :param str gender: Gender of name to generate, one of 'male' or 'female'. If not specified, either gender can be generated. (optional) :param str part: Part of the name to generate, one of 'first' or 'last'. If not specified, full names are generated. (optional) :param bool snake_case: If True, generate a name in "snake_case" format, also stripping diacritics if any. (default: False) :param bool weighted: If True, generate names according to their relative popularity. (default: False) :return str: The generated name. """

        if weighted:
            get_random_name = self._get_weighted_random_name
        else:
            get_random_name = self._get_random_name

        if gender == 'male':
            first_names = self._male_names
        elif gender == 'female':
            first_names = self._female_names
        else:
            first_names = self._names

        name = ''
        surname = ''

        if part == 'first':
            name = get_random_name(first_names)
        elif part == 'last':
            surname = get_random_name(self._surnames)
        else:
            name = get_random_name(first_names)
            surname = get_random_name(self._surnames)

        return self._format_name(name, surname, snake_case=snake_case)