How can I speed up the following for loops in Python? It takes such a long time and renders the code extremely inefficiently. Any help would be much appreciated.
for