1👍
Your question isn’t totally clear, but I think you want a defaultdict which itself contains a defaultdict of lists. So:
class_details = defaultdict(lambda: defaultdict(list))
Alternatively, you may not need a nested dict at all; you could instead use the original defauldict with key that is a tuple:
class_details[(cls.day, cls.period)].append(cls)
Source:stackexchange.com