Function to remove elements from a list working, but Python Hangs :((
Steve Holden
steve at holdenweb.com
Mon Jun 12 07:21:26 EDT 2006
Girish Sahani wrote:
>>I guess it's already the case with lst = [ e for e in lst if e in pairs ]
>>
>>
>>In [1]: lst = (1,2,3,4)
>>
>>In [2]: pairs=(5,)
>>
>>In [3]: lst=[e for e in lst if e in pairs]
>>
>>In [4]: lst
>>Out[4]: []
>
> Yes its working. I realized that i was giving an input which didnt satisfy
> the condition.
> Now if you could please check out this new problem i'm facing,related to
> this.In my code,l4 is a list of lists, and these lists contain such pairs.
> e.g. l4 =
> [[[4,2],[4,7],[4,10],[4,12],[9,2],[9,7],[9,10],[9,12],[11,2],[11,10]],[[1,2],[3,5],[7,8]]]
> which is a list of 2 lists (having 13 pairs)
> Now when l4 has 50 pairs, and i run the code, python just hangs, and i'm
> quite sure its because of this. Is there any way to rectify this???
>
Yes: use standard debugging techniques.
You might try adding "print" statements to show you the value of various
names as you run through the code: frequently this is good enough to
explain what's going wrong (although you *do* need enough confidence to
be able to predict what the values should be).
If all else fails try the "stuffed bear" technique: sit an inanimate
object in front of you and explain the code, and exactly why it can't
possibly be going wrong. Amazingly often, halfway through your
explanation you realise what your error is.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Love me, love my blog http://holdenweb.blogspot.com
Recent Ramblings http://del.icio.us/steve.holden
More information about the Python-list
mailing list