Skip to main content
added 23 characters in body
Source Link
bconstanzo
  • 586
  • 4
  • 10

An interesting point that has been hinted, but not explained, is that extend is faster than append. Any forFor any loop with anthat has append inside should be considered to be replaced by an extendlist.extend(processed_elements).

Bear in mind that apprending new elements might result in the realloaction of the whole list to a better location in memory. If this is done several times because we are appending 1 element at a time, overall performance suffers. In this sense, list.extend is analogous to "".join(stringlist).

An interesting point that has been hinted, but not explained, is that extend is faster than append. Any for loop with an append inside should be considered to be replaced by an extend.

Bear in mind that apprending new elements might result in the realloaction of the whole list to a better location in memory. If this is done several times because we are appending 1 element at a time, overall performance suffers. In this sense, list.extend is analogous to "".join(stringlist).

An interesting point that has been hinted, but not explained, is that extend is faster than append. For any loop that has append inside should be considered to be replaced by list.extend(processed_elements).

Bear in mind that apprending new elements might result in the realloaction of the whole list to a better location in memory. If this is done several times because we are appending 1 element at a time, overall performance suffers. In this sense, list.extend is analogous to "".join(stringlist).

Source Link
bconstanzo
  • 586
  • 4
  • 10

An interesting point that has been hinted, but not explained, is that extend is faster than append. Any for loop with an append inside should be considered to be replaced by an extend.

Bear in mind that apprending new elements might result in the realloaction of the whole list to a better location in memory. If this is done several times because we are appending 1 element at a time, overall performance suffers. In this sense, list.extend is analogous to "".join(stringlist).