Implementing clustering using Python