[Tutor] design question -- nested loops considered harmful?

Alan Gauld alan.gauld at freenet.co.uk
Tue Nov 30 21:37:05 CET 2004


> or, more like your code:
> for line in list_of_lines:
>    if reduce( operator.or_, [line.startswith(flag) for flag in
flags] ) :
>      doSomething()
>      break

While this does reduce the indentation levels and therefore
the theoretical complexity, it introduces two implicit nested
loops which will hit performance: both reduce and the list
comprehension iterate over their respective lists.

Which once again shows the careful thought and selection of
which compromises are important - clarity and brevity
and possibly reliability vv performance in this case.

Alan G.



More information about the Tutor mailing list