[perl-python] problem: reducing comparison (erratum)
Xah Lee
xah at xahlee.org
Wed Feb 16 17:15:08 EST 2005
Xah Lee wrote:
> In imperative languages such as Perl and Python
> and Java, in general it is not safe to delete
> elements when looping thru a list-like entity.
> (it screws up the iteration) One must make a
> copy first, and work with the copy.
Correction:
When looping thru a list-like entity and delete elements in the vary
list, there's a question whether it will change the iteration. (For
example, if one loops thru 1 to 9, and deleted 8 while at 2, should the
loop still do 8?) This is a design issue. Both behavior are useful. For
some languages and or list entities, the answer may be yes or no.
However, in imperative languages such as Perl and Python and Java,
often modifying a list while looping simply cannot be done, justified
as a protection to safeguard programers as ignoramuses, but partially
because the internal issues of these languages. (These languages have
molded a generation of programers to question and discourse man-made
complexities.)
The work around in these languages is always to make a copy of the
list-entity, and work with the copy.
Xah
xah at xahlee.org
http://xahlee.org/PageTwo_dir/more.html
More information about the Python-list
mailing list