I was trying to create a defaultdict where the key was used as a parameter to create a classed object, but I get a TypeError when I try. I've put a minimum example below
from collections import defaultdict
class Intersection:
def __init__(self,xy):
self.position = xy
self.stuff = []
def add(self,stuff):
self.stuff.append(stuff)
intersections: defaultdict[tuple[int,int],Intersection] = defaultdict(lambda xy: Intersection(xy))
intersections[(1,2)].add('stuff')
>>> TypeError: <lambda>() missing 1 required positional argument: 'xy'
I googled the error and it came up with this post which is close to what I'm trying to do but just far enough not to be able to answer how to do this