aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJake <[email protected]>2017-09-20 21:08:46 -0700
committerGitHub <[email protected]>2017-09-20 21:08:46 -0700
commit3e00e7fe8af80654c61ebc08a3ac379b0ff3603d (patch)
tree0312df0c8af862731ec9dfbf658caef67fad7b1f
parentChanged README from using Markdown to use reStructuredText (diff)
downloaddiscord.py-3e00e7fe8af80654c61ebc08a3ac379b0ff3603d.tar.xz
discord.py-3e00e7fe8af80654c61ebc08a3ac379b0ff3603d.zip
[guild] use a defaultdict in by_category
-rw-r--r--discord/guild.py11
1 files changed, 3 insertions, 8 deletions
diff --git a/discord/guild.py b/discord/guild.py
index 23eb8ebc..bdb06403 100644
--- a/discord/guild.py
+++ b/discord/guild.py
@@ -27,7 +27,7 @@ DEALINGS IN THE SOFTWARE.
import copy
import asyncio
-from collections import namedtuple
+from collections import namedtuple, defaultdict
from . import utils
from .role import Role
@@ -332,17 +332,12 @@ class Guild(Hashable):
List[Tuple[Optional[:class:`CategoryChannel`], List[:class:`abc.GuildChannel`]]]:
The categories and their associated channels.
"""
- grouped = {}
+ grouped = defaultdict(list)
for channel in self._channels.values():
if isinstance(channel, CategoryChannel):
continue
- try:
- channels = grouped[channel.category_id]
- except KeyError:
- channels = grouped[channel.category_id] = []
-
- channels.append(channel)
+ grouped[channel.category_id].append(channel)
def key(t):
k, v = t