[Python-Dev] List copy and clear (was Re: Inconsistent API for sets.Set and build-in set) (original) (raw)

Raymond Hettinger python at rcn.com
Fri Jul 1 00:35:51 CEST 2005


[Shane Holloway]

I would agree generic clearing is a lark in terms of programming feature. However, I have been asked how to clear a list more than a handful of times.

list.clear() does not solve the root problem. The question is symptomatic of not understanding slicing. Avoidance of that knowledge doesn't help the person at all. Slicing is part of Python 101 and is basic to the language. There is a reason this subject is presented right at the beginning of the tutorial.

By the time a person is writing apps that modify lists in-place (clearing and rebuilding), then they need to know how lists work. So, a better solution is to submit a doc patch to improve the tutorial's presentation on the subject.

IMO, there is a much stronger case for Fredrik's proposed join() builtin. That addresses an issue that feels warty on the first day you learn it and still feels that way years later.

Raymond



More information about the Python-Dev mailing list