On Jun 8, 2009, at 06:44 , Alasdair wrote:
> This is more of a python question than a Sage question, but
> anyway...
FYI, the Python site has plenty of documentation; the Library
reference manual would have provided the answer.
> I'm trying to iterate over a list, producing a sequence of
> new lists, each of which is obtained from the original list by
> deleting one object. I've tried:
>
> for x in lst:
> lstc=copy(lst)
> print lstc.remove(x)
>
> But this doesn't work - can anybody tell me what I'm doing wrong, and
> what I should be doing?
The first thing to know is that it helps us to diagnose the problems
you are having if you provide some indication of what "it doesn't
work" means. In particular, what is not happening that should, or
what is happening that should not.
> I can get the effect I want by iterating over
> the indices of the list, but I'd like to know why this little snippet
> of code doesn't work.
You are incorrectly assuming that lstc.remove() returns a value. It
does not. The remove() method modifies the input list. This should
do what you want:
for x in lst:
lstc = copy(lst)
lstc.remove(x)
print lstc
HTH
Justin
--
Justin C. Walker
Curmudgeon-at-large
Director
Institute for the Absorption of Federal Funds
----
186,000 Miles per Second
Not just a good idea:
it's the law!
----
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---