def by_category(self):
grouped = defaultdict(list)<EOL>for channel in self._channels.values():<EOL><INDENT>if isinstance(channel, CategoryChannel):<EOL><INDENT>continue<EOL><DEDENT>grouped[channel.category_id].append(channel)<EOL><DEDENT>def key(t):<EOL><INDENT>k, v = t<EOL>return ((k.position, k.id) if k else (-<NUM_LIT:1>, -<NUM_LIT:1>), v)<EOL><DEDENT>_get = self._channels.get<EOL>as_list = [(_get(k), v) for k, v in grouped.items()]<EOL>as_list.sort(key=key)<EOL>for _, channels in as_list:<EOL><INDENT>channels.sort(key=lambda c: (c._sorting_bucket, c.position, c.id))<EOL><DEDENT>return as_list<EOL>
Returns every :class:`CategoryChannel` and their associated channels.

        These channels and categories are sorted in the official Discord UI order.

        If the channels do not have a category, then the first element of the tuple is
        ``None``.

        Returns
        --------
        List[Tuple[Optional[:class:`CategoryChannel`], List[:class:`abc.GuildChannel`]]]:
            The categories and their associated channels.