As a minor style remark, I would prefer that here, and below in the 'diag', you use a tuple rather than a list: (5, 6, 7). Tuples are actually cheaper to instantiate than lists. Not that it really makes a difference.