filtering a list

Terry Reedy tjreedy at
Mon Aug 23 20:39:37 CEST 1999

In article <yILNBDAxDVw3EwSE at>, 
robin at says...
[posted and emailed]

>I'm uncertain as to whether this kind of construct is well formed
>R is a list of instances
>for i in R:
>  if del R[R.index(i)]

I believe that modifying the for-list is unwise since i will never be 
pointed at item after that deleted when its reference is shifted down 
into now empty slot.  IE, 'for' creates internal index but not internal 

>or is it better (assuming R holds the only references to the instances)
>to do
>R=filter((lambda x:,R)
>Robin Becker

In this case yes.
Terry J. Reedy

More information about the Python-list mailing list