On Tue, 11 Nov 2008 11:47:53 -0800, Eric wrote:
> I'm learning Python (while coming from MATLAB). One question I have is
> that if I have a list with say 8 elements, and I want just a few of them
> how do I select them out. In MATLAB, if I just want the first, fifth and
> eighth element I might do something like this:
>
> b = a([1 5 8]);
>
> I can't seem to figure out a similar Python construct for selecting
> specific indices. Any suggestions?
b = [a[i] for i in [1, 5, 8]]
Ciao,
Marc 'BlackJack' Rintsch
--
http://mail.python.org/mailman/listinfo/python-list