Error in Chain of Function calls

Boris Borcic bborcic at gmail.com
Fri Jun 9 08:03:25 EDT 2006


Girish Sahani wrote:
> 
> Also,i am getting a ValueError in the code below:
> 
>               for s in prunedNew:
>                 substrings = [s[:i]+s[i+1:] for i in range(len(s))]
>                 for string in substrings:
>                     if string not in prunedK:
>                         prunedNew.remove(s)
>                         continue
>                     continue
> 
> The error is:
> prunedNew.remove(s)
> ValueError: list.remove(x): x not in list
> 
> Could anyone enlighten me as to why i'm getting these two errors??

Why don't you use sets instead of lists ? It would make your life much easier.

Specifically here, the problem seems to be that for some s there is more than 
one substring of it that fails to be in prunedK, so that the failing line is 
called more than once for a single s.

The simplest modification is to replace your first 'continue' by a 'break' (and 
remove the second 'continue' which serves no purpose).




More information about the Python-list mailing list