Raymond Hettinger wrote:
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.
I tend to not agree. I don't think it is symptomatic of "not understanding slicing", but instead of "not being in a slicing state of mind". What I see in day-to-day is that when programmers want to clear a list, they are sometimes in a situation where you have some persistent list that need to be cleared, so the first reflex is not to think about slicing. They end up in a situation where they only use slicing to clear the lists they use, when their problem has nothing to do with slicing IMHO.
But I understand that would add yet another way to clear a list, while the function is necessary for sets and dictionaries.