As an FYI, this can be written more succinctly as:
```python
if category_name not in self.nodes:
    ...
```

Python objects can override the behaviour for all standard operators via [magic methods](http://www.rafekettler.com/magicmethods.html#sequence). When you write an expression of the form `thing in stuff`, this is essentially syntactic sugar for a call to `stuff.__contains__(thing)`. The built-in `dict` does exactly this so we can avoid retrieving and searching the keys list directly.