Loops in Python - comparison and performance