def __getitem__(self, key):
    if isinstance(key, str):
        try:
            return next((i for i in self.nodes if (getattr(i, 'name', None) == key)))
        except StopIteration:
            raise KeyError(key)
    return self.nodes[key]
def __getitem__(self, key):
    if isinstance(key, str):
        try:
            return next((i for i in self.nodes if (getattr(i, 'name', None) == key)))
        except StopIteration:
            raise KeyError(key)
    return self.nodes[key]