Alasdair wrote:
> This is more of a python question than a Sage question, but
> anyway...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? 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.
The problem is that
lstc.remove(x)
modifies lstc in place and doesn't return anything. So you aren't
printing anything. The following should do what you want:
for x in lst:
lstc = copy(lst)
lstc.remove(x)
print lstc
HTH,
Jason
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---