Simple question about Python lists

Scott David Daniels Scott.Daniels at Acm.Org
Wed Nov 12 16:08:49 EST 2008


Eric wrote:
> ... In MATLAB, if I just want the first, fifth and eighth element I
> might do something like this:   b = a([1 5 8]);

On Nov 11, 1:51 pm, Marc 'BlackJack' Rintsch <bj_... at gmx.net> replied:
>> b = [a[i] for i in [1, 5, 8]]

To which Eric said:
> Thanks! It makes sense, but in this case MATLAB seems easier and no
> less readable. That said, I know better than for a newbie like me to
> question syntax issues.

If you are using numpy, you may find found the following link useful:

     http://www.scipy.org/NumPy_for_Matlab_Users

--Scott David Daniels
Scott.Daniels at Acm.Org



More information about the Python-list mailing list