This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author rhettinger
Recipients eric.smith, paul.moore, rhettinger, sreedevi.ha, steven.daprano, terry.reedy
Date 2020-09-24.22:33:30
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
> The usually recommended alternative is to make a new list of 
> things not deleted.  But one can do this in-place by writing
> the new list on top of the old by using a explicit second 
> index to move items just once.

I don't think we should send users down this path.  Better to stick with high level, easy-to-implement and performant suggestions:

To edit a list in-place it is often simplest and fastest to replace the entire list:

   colors[:] = [color for color in colors if websafe(color)]

This makes a single pass through the list and efficiently builds a new list.  The colors[:] then replaces the entire contents of the original list with the new list

Besides being easy to get right, this is likely to be *much* faster than tracking two indicies to manipulate the array in-place.  Slice operations run at the speed of a C memcpy (plus the ref count changes) and don't involve creating and destroying integer objects for indexing.
Date User Action Args
2020-09-24 22:33:31rhettingersetrecipients: + rhettinger, terry.reedy, paul.moore, eric.smith, steven.daprano, sreedevi.ha
2020-09-24 22:33:31rhettingersetmessageid: <>
2020-09-24 22:33:31rhettingerlinkissue41774 messages
2020-09-24 22:33:30rhettingercreate