Skip to content

Commit

Permalink
Use defaultdict in bysize.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaraco committed Oct 20, 2022
1 parent 7638e3f commit 8c0082d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions inflect/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import ast
import re
import functools
import collections
import contextlib
from typing import (
Dict,
Expand Down Expand Up @@ -148,12 +149,10 @@ def bysize(words: Iterable[str]) -> Dict[int, set]:
>>> ret[5]
{'horse'}
"""
ret: Dict[int, set] = {}
res: Dict[int, set] = collections.defaultdict(set)
for w in words:
if len(w) not in ret:
ret[len(w)] = set()
ret[len(w)].add(w)
return ret
res[len(w)].add(w)
return res


def make_pl_si_lists(
Expand Down

0 comments on commit 8c0082d

Please sign in to comment.