* and because Guido believes beginners tend to copy too much
(that is one reason why copy.copy is not a builtin) and that
the language should encourage correct behavior.
OTOH, beginners tend to copy not enough - when for example iterating over a
list being acting upon.
Though my real
Arthur wrote:
If the thought is that hiding copy, or relying on idioms for a
construct as fundamental as the list - is a favor to the beginner,
I very much am not.
I don't think anyone believes that. It's more a feeling that
Python shouldn't be cluttered up with things that are *only*
for
Raymond Hettinger wrote:
Several thoughts:
As I told you in a private dicussion, you have convinced me about copy.
About clear, however, I feel I have to defend my colleagues and
myself, who almost all wasted time once (but only once) searching how to
clear a list. Improving the docs (like
Barry Warsaw wrote:
I've been looking at the API for sets.Set and built-in set objects in
Python 2.4.1 and I think I have found some minor inconsistencies.
This comment reminds me another small inconsistency/annoyance.
Should copy and clear functions be added to lists, to be more consistent
[Nicolas Fleury]
This comment reminds me another small inconsistency/annoyance.
Should copy and clear functions be added to lists, to be more
consistent
with dict and set, and easing generic code?
I think not.
Use copy.copy() for generic copying -- it works across a wide range of
objects.
On Thursday 30 June 2005 17:26, Raymond Hettinger wrote:
the current idiom:
mylist[:] = [] # clear
Unless you happen to prefer the other current idiom:
del mylist[:]
-Fred
--
Fred L. Drake, Jr. fdrake at acm.org
___
Raymond Hettinger wrote:
I would think that that generic clearing is a lark. First, it only
applies to mutable objects. Second, it would likely only be useful in
the presence of a generic method for adding to the cleared container (as
opposed to the existing append(), add(), and setitem()
[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
Raymond Hettinger wrote:
Use copy.copy() for generic copying -- it works across a wide range of
objects. Alternatively, use the constructor as generic way to make
duplicates:
dup = set(s)
dup = list(l)
dup = dict(d)
dup = tuple(t) # note, the duplicate is original object
Raymond Hettinger wrote:
[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
Raymond Hettinger wrote:
Use copy.copy() for generic copying -- it works across a wide range
of
objects. Alternatively, use the constructor as generic way to make
duplicates:
dup = set(s)
dup = list(l)
dup = dict(d)
dup = tuple(t) # note, the duplicate is original
11 matches
Mail list logo