Antony Lee <anntzer....@gmail.com> added the comment: > But with a list or other sequence with a known length, the interpreter can > allocate the right number of items up front, and avoid growing or shrinking > the new list. I believe that this is the time saving you are seeing.
But certainly when the list comprehension is executed the interpreter also needs to pay that cost? (It cannot know a priori that `[x for x in range(100)]` will have 100 elements, as `range` may have been shadowed at that point.) Yes, the price is not paid when running `sorted` itself, but it should be paid when creating the list from the comprehension? ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue32945> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com