Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Ellipsis usage?

Reply
Thread Tools

Ellipsis usage?

 
 
Wayne Folta
Guest
Posts: n/a
 
      02-18-2004
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?


 
Reply With Quote
 
 
 
 
Christophe Delord
Guest
Posts: n/a
 
      02-18-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.
 
Reply With Quote
 
 
 
 
Peter Otten
Guest
Posts: n/a
 
      02-18-2004
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?


The Nutshell has it in the chapter about the Numeric package (but not in the
index), and Numeric is the only package I know of that uses the ellipsis:

>>> a = Numeric.reshape(range(, (2,2,2))
>>> a

array([[[0, 1],
[2, 3]],
[[4, 5],
[6, 7]]])
>>> a[1,1,1]

7
>>> a[:,:,1]

array([[1, 3],
[5, 7]])

This can be abbreviated:

>>> a[...,1]

array([[1, 3],
[5, 7]])

Another example:

>>> a[1,...,1]

array([5, 7])
>>> a[1,:,1]

array([5, 7])

I. e. you can specify the leading and the trailing dimension(s), and the
ellipsis inserts defaults for the intermediate dimensions.

Peter

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
The Ellipsis (.) Character Is Not Showing Up When Read From A Text File Nathan Sokalski ASP .Net 2 02-14-2006 08:49 AM
doctest's ELLIPSIS =?iso-8859-1?q?S=E9bastien_Boisg=E9rault?= Python 5 05-02-2005 11:51 AM
slicing, mapping types, ellipsis etc. Jerry Sievers Python 9 11-30-2004 02:26 PM
!wtf ellipsis =?iso-8859-1?q?Jonas_K=F6lker?= Python 6 08-14-2004 11:05 PM
Ellipsis outside a slice Chris Perkins Python 1 10-09-2003 02:10 AM



Advertisments