<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def retire(self, process_schemas):
 """Retire obsolete processes. Remove old process versions without data. Find processes that have been registered but do not exist in the code anymore, then: - If they do not have data: remove them - If they have data: flag them not active (``is_active=False``) """

        process_slugs = set(ps['slug'] for ps in process_schemas)

        # Processes that are in DB but not in the code
        retired_processes = Process.objects.filter(~Q(slug__in=process_slugs))

        # Remove retired processes which do not have data
        retired_processes.filter(data__exact=None).delete()

        # Remove non-latest processes which do not have data
        latest_version_processes = Process.objects.order_by('slug', '-version').distinct('slug')
        Process.objects.filter(data__exact=None).difference(latest_version_processes).delete()

        # Deactivate retired processes which have data
        retired_processes.update(is_active=False)