[issue41590] "zip()" very slowly for this

email0.ya report at bugs.python.org
Wed Aug 19 16:09:48 EDT 2020


email0.ya <email0.ya at yandex.com> added the comment:

Above is a link to part of the tutorial. An example with a for statement at the beginning is good. I am not saying that it needs to be replaced with something. The above example reads: "A list comprehension consists of brackets containing an expression followed by a for clause, then zero or more for or if clauses".
________________________________
def transpose1_3_1 (a: list) -> list:
    "" "Transpose matrix version 1.3.1" ""
    max_j = len (max (a))
    return [
        [row [j] if j <len (row)
                    else 0 for row in a]
            for j in range (max_j)]
_______________________________
Here a list comprehension consists of brackets containing an expression followed by a if clause, then else and for clause in end.
It is clear that the above is written inaccurately (i.e. it can be corrected).
I think it's a good idea to add a similar example with an if statement at the beginning.
At the end it says: “In the real world, you should prefer built-in functions to complex flow statements. The zip () function would do a great job for this use case".
It's good that this is said here about this function. I agree with the first sentence. Disagree that zip () function would do a great job for this use case (Transpose).
The examples in the tutorial only demonstrate the possibilities, they should be simple, I understand. But, they cannot be used to solve a problem with a small change in the value of variables, and this can be done very simply. The zip () function not only performed the transpose slower than even the first function, but it also cannot execute it if the argument values change slightly. She only repeated what could only work in this particular case.
It's good if the algorithms work more efficiently. It's not okay to use slow algorithms. And it would be nice if programmers, reading the tutorial, would write fast algorithms.
I already know about timeit. Thank. I have calculated the arithmetic mean for many cases. The results were stable.
I wish you good.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue41590>
_______________________________________


More information about the Python-bugs-list mailing list