[Tutor] In-place expansion of list members... possible?
Marc Tompkins
marc.tompkins at gmail.com
Wed Nov 7 22:04:34 CET 2007
> > What puzzles me most is that I can replace 'seg' with just about
> > anything else -
> > for seg in tmpSegs:
> > seg = seg.strip()
> > or
> > for seg in tmpSegs:
> > seg = 'bananas'
> > or
> > for seg in tmpSegs:
> > seg = seg + ' bananas'
> > and it works. So why can't I replace it with its own split?
>
> If by 'it works' you mean that tmpSegs is changed...you are mistaken or
> there is something you are not showing. Can you show why you think this
> changes tmpSegs?
I see I have been misled by trying too many things in a short time and
confusing my results. I could have sworn that late last night, before I hit
on the solution of assigning to a new list altogether, I tried the above
examples and followed them with another "for seg in tmpSegs" loop that
simply printed the contents.
I now suspect myself of being too sleepy (and probably inadvertently
assigning to a new list anyway!) at the time, because - as you already know
- when I try it now, tmpSegs is unchanged. I hang my head in shame.
Thanks for the responses -
Marc
--
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20071107/cc9ff192/attachment.htm
More information about the Tutor
mailing list