[Tutor] how to make a reference to part of list?
Kent Johnson
kent37 at tds.net
Mon Oct 2 14:49:05 CEST 2006
Xie Chao wrote:
> 3Q very much!
> What I really want to get is a c-style array, a pointer to the
> beginning of part of a list (or whatever alike). for example, I want to
> mutate part of a list, of course, I can achieve this by passing the pair
> list and (begin, end) as parameters. but in some case, this manner
> is quite tedious and in efficient (I think so, at least in C-style
> language it is so)!
> I don't wanna get the '+' operator (which is powerful tool in
> scripting language), so I ignore this problem. thank you all the same!
> maybe this prolem looks silly, since I've just begun to
> study scripting language.
Take a look at numpy, it seems to do what you want:
In [2]: from numpy import *
In [4]: a=arange(10)
In [5]: a
Out[5]: array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
In [6]: b=a[3:5]
In [7]: b
Out[7]: array([3, 4])
In [8]: b[0]=10
In [9]: b
Out[9]: array([10, 4])
In [10]: a
Out[10]: array([ 0, 1, 2, 10, 4, 5, 6, 7, 8, 9])
http://numpy.scipy.org/
Kent
More information about the Tutor
mailing list