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

2005-07-05 Thread Arthur
* 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

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

2005-07-05 Thread Greg Ewing
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

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

2005-07-01 Thread Nicolas Fleury
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

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

2005-06-30 Thread Nicolas Fleury
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

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

2005-06-30 Thread Raymond Hettinger
[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.

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

2005-06-30 Thread Fred L. Drake, Jr.
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 ___

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

2005-06-30 Thread Shane Holloway (IEEE)
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()

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

2005-06-30 Thread Raymond Hettinger
[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

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

2005-06-30 Thread Nicolas Fleury
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

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

2005-06-30 Thread Nicolas Fleury
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

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

2005-06-30 Thread Raymond Hettinger
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