mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-05-09 23:39:50 +00:00
[guild] use a defaultdict in by_category
This commit is contained in:
parent
06296bfaf6
commit
3e00e7fe8a
@ -27,7 +27,7 @@ DEALINGS IN THE SOFTWARE.
|
|||||||
import copy
|
import copy
|
||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from collections import namedtuple
|
from collections import namedtuple, defaultdict
|
||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from .role import Role
|
from .role import Role
|
||||||
@ -332,17 +332,12 @@ class Guild(Hashable):
|
|||||||
List[Tuple[Optional[:class:`CategoryChannel`], List[:class:`abc.GuildChannel`]]]:
|
List[Tuple[Optional[:class:`CategoryChannel`], List[:class:`abc.GuildChannel`]]]:
|
||||||
The categories and their associated channels.
|
The categories and their associated channels.
|
||||||
"""
|
"""
|
||||||
grouped = {}
|
grouped = defaultdict(list)
|
||||||
for channel in self._channels.values():
|
for channel in self._channels.values():
|
||||||
if isinstance(channel, CategoryChannel):
|
if isinstance(channel, CategoryChannel):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
try:
|
grouped[channel.category_id].append(channel)
|
||||||
channels = grouped[channel.category_id]
|
|
||||||
except KeyError:
|
|
||||||
channels = grouped[channel.category_id] = []
|
|
||||||
|
|
||||||
channels.append(channel)
|
|
||||||
|
|
||||||
def key(t):
|
def key(t):
|
||||||
k, v = t
|
k, v = t
|
||||||
|
Loading…
x
Reference in New Issue
Block a user