Skip to main content
added 145 characters in body
Source Link
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).

The article on Analysis of Algorithms in Wikipedia might me useful for you.

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).

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).

The article on Analysis of Algorithms in Wikipedia might me useful for you.

Source Link
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).