Distance Vector algorithm in Python