def by_user(self):  # pragma: no cover
        """
        Display group membership sorted by group.

        Returns:
            Array with a dictionary of group membership.
                For example: {'test.user': ['testgroup', 'testgroup2']}

        """
        users = [i for i in self.__get_users()]
        user_groups = {}
        group_results = {
            tuple(value): key
            for (key, value) in self.by_group().items()
        }
        for user in users:
            user_groups[user] = []
            for user_list, group in group_results.items():
                if user in user_list:
                    user_groups[user].append(group)

        return user_groups