Skip to content

Commit

Permalink
refactor: use defaultdict in group_links for cleaner code
Browse files Browse the repository at this point in the history
  • Loading branch information
amerkurev committed Jan 14, 2024
1 parent 0f2759f commit 358c2cd
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions app/routers/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import datetime
import hashlib

from collections import defaultdict
from operator import itemgetter
from statistics import median

Expand Down Expand Up @@ -155,12 +156,9 @@ def allowed_domain(href: str, domain: str) -> bool:

def group_links(links: Sequence[Mapping]) -> dict:
# group links by 'CSS selector', 'color', 'font', 'parent padding', 'parent margin' and 'parent background color' properties
links_dict = {}
links_dict = defaultdict(list)
for link in links:
key = make_key(link)
if key not in links_dict:
links_dict[key] = []
links_dict[key].append(link)
links_dict[make_key(link)].append(link)
return links_dict


Expand Down

0 comments on commit 358c2cd

Please sign in to comment.