Used standard library definition

This commit is contained in:
Brandon Rozek 2020-04-14 14:21:31 -04:00
parent 8fa4691511
commit 1f7c6f10ab

View file

@ -1,37 +1,9 @@
from collections import Counter
from collections import Counter, defaultdict
from typing import Dict, List, Any
import numpy as np
import torch
class Logger:
"""
Keeps track of lists of items seperated by tags.
Notes
-----
Logger is a dictionary of lists.
"""
def __init__(self):
self.log = {}
def append(self, tag, value):
if tag not in self.log.keys():
self.log[tag] = []
self.log[tag].append(value)
def clear(self):
self.log.clear()
def keys(self):
return self.log.keys()
def __len__(self):
return len(self.log)
def __iter__(self):
return iter(self.log)
def __contains__(self, value):
return value in self.log
def __getitem__(self, index):
return self.log[index]
def __setitem__(self, index, value):
self.log[index] = value
def __reversed__(self):
return reversed(self.log)
Logger: Dict[Any, List[Any]] = defaultdict(list)
class LogWriter:
"""