def _get_grouped_releases(self, get_release_func): releases = NextcloudRelease.objects.all() versions = map(lambda r: r.version, releases) compatible_releases = map(lambda v: (v, get_release_func(v)), versions) grouped_releases = group_by_main_version(dict(compatible_releases)) # deduplicate releases result = {} for version, releases in grouped_releases.items(): result[version] = list(distinct(releases, lambda r: r.version)) return result