New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"zip()" very slowly for this #85756
Comments
https://docs.python.org/3.9/tutorial/datastructures.html |
What are you actually reporting? What part of the documentation do you think should be changed, why should it be changed, and what should it be changed to? It is normal for different algorithms to perform with different speed. I'm not sure what the purpose of the "nested_lists" file is. You have discovered that different programs perform differently. Okay. What do you want us to do? One last comment: using time() as you did is unreliable, especially for small code snippets that are very fast. The best way to time small snippets of Python code is to use the timeit module. |
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: Here a list comprehension consists of brackets containing an expression followed by a if clause, then else and for clause in end. |
First, what you wrote with if...else is _not_ "if clause". It's a conditional expression. You'll recognize them easily if you remember that "if clause" in comprehensions never has an "else", while conditional expression always does. Second, speed is just one of many, many criteria by which we evaluate programs. If only speed matters to you, you probably shouldn't be writing in Python at all. There are much faster languages. |
Third, where did you get the idea that transposing a "matrix" consisting of lists of varying length is a sensible operation? Your reference (Wikipedia) tells nothing about that case. I've never seen [[],[1]] called "a matrix". |
If you know about timeit, why aren't you using it? In any case, I have just ran your nested_lists.py file, and on my 0 transpose1_0(lT) Time = 1.0627508163452149e-05 1.55e-6 is smaller than 1.06e-5:
Smaller times are faster, and the first version transpose1_0 takes As for the other comments, the purpose of the tutorial is to teach the Making the example more complicated so that it is a tiny bit faster You are also confused about the structure of comprehensions. The
There is no else-part in the comprehension, and the for-part always
is not an "if statement" as you call it, neither is it part of the See the full language specification, in particular the grammar: https://docs.python.org/3.9/reference/grammar.html We could re-write the if-expression like this:
That doesn't mean that comprehensions consist of an "and" part followed Adding this level of technical detail and complexity to an introductory |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: