[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 01:33:11 CEST 2005
- Previous message: [Python-Dev] List copy and clear (was Re: Inconsistent API for sets.Set and build-in set)
- Next message: [Python-Dev] List copy and clear (was Re: Inconsistent API for sets.Set and build-in set)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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 here :-)
[Nicolas Fleury]
I know all this, but why then is there a copy method for sets and dictionaries? What justification is valid for sets and dictionaries that doesn't apply to lists?
Several thoughts:
maybe it's a Dutch thing;
dict.copy() pre-dated dict(d) and (IIRC) copy.copy();
sets and dicts don't have the [:] syntax available to them;
the copy() method is new way to make things copy.copyable without fattening the apparent API or rewriting the copy module;
because generic copying isn't important enough to add more ways to do the same thing;
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.
Raymond
- Previous message: [Python-Dev] List copy and clear (was Re: Inconsistent API for sets.Set and build-in set)
- Next message: [Python-Dev] List copy and clear (was Re: Inconsistent API for sets.Set and build-in set)
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]