day12: defaultdicts ... TIL
This commit is contained in:
parent
457be373ff
commit
86745e1d2c
16
day12.py
16
day12.py
@ -1,19 +1,13 @@
|
|||||||
|
from collections import defaultdict
|
||||||
from tools.aoc import AOCDay
|
from tools.aoc import AOCDay
|
||||||
from typing import Any, Dict, List
|
from typing import Any, Dict, List
|
||||||
|
|
||||||
|
|
||||||
def getCaveMap(lines: List[List[str]]) -> Dict[str, List[str]]:
|
def getCaveMap(lines: List[List[str]]) -> Dict[str, List[str]]:
|
||||||
m = {}
|
m = defaultdict(list)
|
||||||
for l in lines:
|
for l, r in lines:
|
||||||
if l[0] in m:
|
m[l].append(r)
|
||||||
m[l[0]].append(l[1])
|
m[r].append(l)
|
||||||
else:
|
|
||||||
m[l[0]] = [l[1]]
|
|
||||||
|
|
||||||
if l[1] in m:
|
|
||||||
m[l[1]].append(l[0])
|
|
||||||
else:
|
|
||||||
m[l[1]] = [l[0]]
|
|
||||||
|
|
||||||
return m
|
return m
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user