Ellipsis usage?
Christophe Delord
no.spam
Wed Feb 18 15:21:22 EST 2004
On Wed, 18 Feb 2004 11:39:04 -0500, Wayne Folta wrote:
> I see Ellipsis documented under slicing, though it appears it's not
> used in slicing but rather slicing-like notation for dictionary keys.
> It's a minor thing but none of the books I have even mention it. Is it
>
> obsolete in python 2.x or still useful?
>
>
Hello,
I have used Ellipsis in a project where the ... notation was more
adapted than : (because x:y had another meaning in our context).
I had a class similar to this one:
class MyRange:
def __init__(self, lst):
self.lst = lst
def __getitem__(self, slice):
r = []
items = list(slice)
while items:
a = items.pop(0)
if items[:1] == [Ellipsis]:
items.pop(0)
b = items.pop(0)
r.extend(self.lst[a:b+1])
else:
r.append(self.lst[a])
return r
r = MyRange(list("abcdefghijklmnopqrstuvwxyz"))
print r[1, 2, 3, 10, ..., 15]
should print ['b', 'c', 'd', 'k', 'l', 'm', 'n', 'o', 'p']
But I don't know exactly what's the real use of Ellipsis and if it will
exist in the future.
More information about the Python-list
mailing list