minor refactoring on graphs.py, add spaces between operators and use comprehensions