[Pythonmac-SIG] Missing orthogonal functions
Michael Hudson
mwh@python.net
Tue, 25 Mar 2003 16:04:32 +0000
AFAICT, this has nothing to do with Macs.
Dan Grassi <dan@grassi.org> writes:
> From an orthogonal viewpoint operations of lists and dictionaries
> that could be orthogonal but are not include: x.copy() and x.append().
Pff! Dictionaries and lists are *different*!
> Obtaining a copy
> In the case of dictionaries there is the d.copy() function but
> this is not available for lists, instead rather obscure syntax
> is used: l.[:]. This is confusing for new python coders, a
> l.copy() function is more intuitive.
There's the copy module for this.
Would you propose adding a do-nothing .copy() method to tuples?
> Adding a value
> For dictionaries d[n] = v is available but this is not always
> viable as in lambda functions in a map operation and list
> comprehension can not be used in all cases.
>
> Doesn't work:
> map(lambda n, v: d[n] = v, names, vars)
>
> Instead something like this must be done:
> td = {}
> map(lambda n, v: td.setdefault(n, v), names, vars)
> d.update(td}
>
> What would be nice:
> map(lambda n, v: d.set(n, v), names, vars)
> Or for a more orthogonality
> map(lambda n, v: d.append(n, v), names, vars)
for name, var in zip(names, vars):
d[name] = var
> Does this make sense?
No more than the zillion times this stuff has been discussed on
comp.lang.python...
learn-to-love-the-return-key-ly y'rs,
M.
--
81. In computing, turning the obvious into the useful is a living
definition of the word "frustration".
-- Alan Perlis, http://www.cs.yale.edu/homes/perlis-alan/quotes.html