def _get_modules_and_forms(self, as_dict=True):
        modules_by_app = collections.defaultdict(list)
        forms_by_app_by_module = {}
        for form in self._all_forms:
            has_app = form.get('has_app', False)
            app_lang = form['app']['langs'][0] if form['app'] in 'langs' else 'en'
            app_id = form['app']['id'] if has_app else self.UNKNOWN_SOURCE
            module = form.get('module')
            module_id = (module['id'] if has_app and module is not None
                         else self.UNKNOWN_SOURCE)
            module_name = self._get_item_name(
                module, has_app, app_lang, _("Unknown Module")
            )
            form_xmlns = form['xmlns']
            form_name = form_xmlns
            if not form.get('show_xmlns', False):
                form_name = self._get_item_name(
                    form.get('form'), has_app, app_lang,
                    "{} (potential matches)".format(form_xmlns)
                )
            module_choice = RMIDataChoice(
                module_id,
                module_name,
                form
            )
            form_choice = RMIDataChoice(
                form_xmlns,
                form_name,
                form
            )
            if as_dict:
                form_choice = form_choice._asdict()

            if app_id not in forms_by_app_by_module:
                forms_by_app_by_module[app_id] = collections.defaultdict(list)
            modules_by_app[app_id].append(module_choice)
            forms_by_app_by_module[app_id][module_id].append(form_choice)

        modules_by_app = self._get_unique_choices(modules_by_app)
        if as_dict:
            modules_by_app = self._map_chosen_by_choice_as_dict(modules_by_app)
        return modules_by_app, forms_by_app_by_module
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/app_manager/fields.py/ApplicationDataRMIHelper._get_modules_and_forms/swapped operands of `in`