python code for building index