Timeline for answer to What is the difference between Python's list methods append and extend? by Nova
Current License: CC BY-SA 3.0
Post Revisions
6 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jul 28, 2019 at 3:43 | comment | added | Soren Bjornstad |
@MadPhysicist: For completeness' sake, there would be times where extend() can't preallocate sensibly since some iterables don't implement __len__(), but like you I'd be surprised if it doesn't try. Some of the performance gain also comes from doing the iteration part in pure C instead of in Python, as pointed out in Aaron's answer.
|
|
| Nov 24, 2016 at 11:00 | history | edited | Kenly | CC BY-SA 3.0 |
indentation
|
| Oct 23, 2015 at 13:43 | comment | added | Mad Physicist |
extend() probably preallocates, while append() likely does not.
|
|
| Dec 27, 2012 at 8:29 | comment | added | Alex L | Extending is ~4x faster on my machine than appending in a loop (16us vs 4us for 100 loops of zeros) | |
| Oct 10, 2012 at 13:02 | history | edited | Nova | CC BY-SA 3.0 |
added 74 characters in body
|
| Aug 20, 2012 at 21:11 | history | answered | Nova | CC BY-SA 3.0 |