Suggestion: PEP for popping slices from lists

Terry Reedy tjreedy at udel.edu
Thu Aug 8 18:10:52 EDT 2013


On 8/8/2013 5:32 PM, Joshua Landau wrote:
> On 8 August 2013 21:03, Terry Reedy <tjreedy at udel.edu> wrote:
>> If .pop were being added today, I would argue against including the index
>> parameter.
>
> GASP! That's no fair!
>
> 1) When using pop you normally want to keep the mutability available,
> so iter(mylist) is a no-go.
> 2) When using the index, it's often somewhere in the middle that
> you're popping from

I have never done that and I do not believe I have ever seen that. It 
certainly is extremely rare in my experience. Removing an item *after* 
looking at it is something different.

for i in range(len(mylist), -1, -1):
   if pred(mylist[i]): del mylist[i]

-- 
Terry Jan Reedy




More information about the Python-list mailing list