how to count iterations in python