Hi Steve

You wrote that we don't need a seq.slice(a, b) method, because the existing
syntax does the job fine.

To change the subject slightly, it seems to me that we don't need both
seq[a:b] and slice(a, b). Certainly, we can get by without either. If we
didn't have seq[a:b] we could use slice(a, b) instead:

>>> lst[10:20]
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]
>>> lst[slice(10, 20)]
[10, 11, 12, 13, 14, 15, 16, 17, 18, 19]

And if we have seq[a:b] then we can get our hands on slice(a, b):

>>> class GetItemArg:
...     def __getitem__(self, arg):
...         return arg

>>> getslice = GetItemArg()
>>> getslice[10:20]
slice(10, 20, None)

A purist might say that seq[a:b] is syntactic sugar for seq[slice(a,b)].
And that it is yet another use of the colon. However, I do find it
convenient and familiar. So I'd like to keep it, and will defend it against
purists who wish to remove it. In that, Steve and I (and I think the
original poster) agree.

I don't think I'd get the same benefit for seq.slice(a, b) being added to
the methods of the built-in sequence types (such as list). But I'd prefer
that the decision would be on pragmatic grounds, based on experience.

I certainly think the meaning of seq.slice(a, b) is clear, and would more
easily discovered than the seq[a:b] notation. Certainly, neither 'slice'
nor ':' appear in
>>> help(list)

A personal interest aside: A list is one-dimensional. Numpy deals with
multi-dimensional rectangular arrays of numbers. In my mathematics area, I
deal with triangles of numbers (think Pascal's Triangle), and also pyramids
of numbers.

(aside continued). Numpy allows 'slicing' and reshaping of its rectangular
arrays. In my mathematics area, I'd like to similarly be able to slice
triangles and pyramids of numbers. For example, the central binomial
coefficients:
http://oeis.org/A000984

Finally, off-topic, I find it a bit odd that in the below we get syntax
errors (rather than a run-time error).

>>> getslice[]
 SyntaxError: invalid syntax
>>> getslice[1:2]
slice(1, 2, None)
>>> getslice[1:2:3]
slice(1, 2, 3)
>>> getslice[1:2:3:4]
SyntaxError: invalid syntax

-- 
Jonathan
_______________________________________________
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/7BONFIUODE4TT667R2EY4YRPDZICKJH4/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to