David Mertz writes:

 > I support named indices.  But I strongly oppose using them in list,
 > tuple, or dict themselves.  So `mylist[99, default=4]` would still
 > be a syntax error (or maybe a different exception).

I don't think it can be a SyntaxError because you can't always know
that mylist is a builtin list.  list.__getitem__(self, ...) gets
called and it tells you "TypeError: __getitem__() takes no keyword
arguments", as it does now.  (Just for the record.  I bet you realized
that within nanoseconds of hitting "send". ;-)

Paul Moore writes:

 > Furthermore, I'd be very, very strongly opposed to having x[i,
 > default=d] be a way of supplying a default result if i isn't present
 > in *any* subscriptable class, and particularly in dict as an
 > equivalent for x.get(i, d). It's redundant,

True, but not really fair under my assumption that `x[i, default=d]`
becomes the accepted way of doing it generally.  dict.get would be a
legacy in that case.

How do you folks feel about list.get and tuple.get (I expect many
folks will think differently about these because tuples are
immutable), and more generally Sequence.get?

 > confusing, and unlike any other language I'm familiar with (all
 > IMO, if that's not obvious...).

All this opposition is interesting.  For reasons similar to those
expressed by MAL for sequences I rarely use dict.get, let alone want
list.get.  To me it usually just feels wrong to be getting something
that might not be there, and then leaving it that way.  I use
defaultdict much more than I use dict.get.

Regarding the statement that it's "unlike any other language," I
suspect that's true; the only possible exception would be Lisps, but I
think the argument that they don't have true indexing ends it.  Partly
by analogy to Lisp, I think of indexing as an optimized case of
function call (which is how it's implemented in Python!  That's just
an amusing observation, not intended seriously.)  The square brackets
basically say "you can expect this operation to be O[1], almost always
with small c" for appropriate values of "small".  So this syntax
doesn't bother me, given that functions support arbitrary keywords.

I guess all this makes me an extremist.  Doesn't stop me from liking
the Python you prefer just as well, though. :-)
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/PR7YZYZXHA6EYCH4PROSNN3HGG3VYLWI/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to