[Python-ideas] if-statement in for-loop

Sven R. Kunze srkunze at mail.de
Wed Oct 5 09:27:16 EDT 2016


On 05.10.2016 11:20, Stephen J. Turnbull wrote:
> Eg, there's no question in my mind that
>
>      for i in range(m):
>          for j in range (n):
>              for k in range (p):
>                  m_out(i, k) += m_in1(i, j) * m_in2(j, k)
>
> is easier to read[1] than
>
>      for i in range(m) for j in range (n) for k in range (p):
>          m_out(i, k) += m_in1(i, j) * m_in2(j, k)
>
> despite costing two lines and two levels of indentation.  YMMV, of
> course, but I suspect most senior devs will disagree with you.

I agree with you on this when it comes to long-living production code.


For small scripts this is still useful. Not everybody writes huge 
programs, which needs to adhere to style guides and QA.


Cheers,
Sven


More information about the Python-ideas mailing list