Function to remove elements from a list not working (corrected)

Paul McGuire ptmcg at austin.rr._bogus_.com
Mon Jun 12 11:13:54 EDT 2006


"Girish Sahani" <girish at cse.iitb.ac.in> wrote in message
news:mailman.6916.1150100741.27775.python-list at python.org...
> Hi,
>  I am trying to modify a list of pairs (l4) by removing those
> pairs which are not present in a third list called pairList.
>  The following is a simplified part of the routine i have written. However
> it does not give the correct output. Please help!
>  Its possible i have made a trivial mistke since i am a newbie.
>

You've fallen victim to one of the Classic Blunders!  The First is "Never
start a land war in Asia!", but the second, only slightly lesser known is
"Never modify a list that you are iterating over!"

-- Paul





More information about the Python-list mailing list