Skip to main content
1 of 2
dsign
  • 12.8k
  • 6
  • 63
  • 83

Loops are not a bad idea. It is just that loop-intensive code can be slow. But it is nothing specific to the loops, it is just that Python is not as fast in general as some other languages. I suggest you do not avoid loops if they are the most natural expression of your algorithm. If your code turns out slower of what you expect or need, then look for ways of optimizing it (profiling, to start with).

dsign
  • 12.8k
  • 6
  • 63
  • 83