referencing disjoint array indexes
Stuart D. Gathman
stuart at bmsi.com
Mon Nov 11 11:09:29 EST 2002
On Mon, 11 Nov 2002 07:28:19 -0500, Padraig Brady wrote:
> Is there any way you can do something like
>
> size, mtime = os.stat()[8,6]
def index(seq,il):
res = [seq[i] for i in il]
if type(seq) == str:
return ''.join(res)
if type(seq) == tuple:
return tuple(res)
return res
size, mtime = index(os.stat(),[8,6])
I proposed the very intuitive syntax you suggest earlier in this group,
and was informed that additional semantic overlays to indexing were Not Welcome
- especially when a function does the trick.
However, a pure python implementation of the index function suffers from
having to copy a list to a tuple. A C version could build the tuple or
string directly - even if still using the function syntax. In your application,
the improvement would be negligible.
The seq[list] notation is particularly natural to me having used APL once
upon a time.
--
Stuart D. Gathman <stuart at bmsi.com>
Business Management Systems Inc. Phone: 703 591-0911 Fax: 703 591-6154
"Confutatis maledictis, flamis acribus addictis" - background song for
a Microsoft sponsored "Where do you want to go from here?" commercial.
More information about the Python-list
mailing list