locate items in matrix (index of lists of lists)

Chris Rebert clp2 at rebertia.com
Fri Mar 20 19:14:41 CET 2009


On Fri, Mar 20, 2009 at 7:28 AM, MRAB <google at mrabarnett.plus.com> wrote:
> Chris Rebert wrote:
>>
>> On Fri, Mar 20, 2009 at 4:34 AM, Alessandro Zivelonghi
>> <zasaconsulting at gmail.com> wrote:
>>>
>>> Many Thanks guys!
>>>
>>> and what if I need to look ONLY into the second and third columns,
>>> excluding the first item of each rows?
>>>
>>> for example if x = 3 I need to get  [0] and not [0,1]
>>
>> indices = [i for i, row in enumerate(mat) if 1<= i <= 2 and 3 in row[1:]]
>>
> If he wants to look in only the second and third columns, but still all
> the rows, surely that's:
>
>    indices = [i for i, row in enumerate(mat) if x in row[1 : 3]]

The OP had his columns and rows mixed up in that last email, if you'll
notice what he gave as his intended output. :-)

Cheers,
Chris

-- 
I have a blog:
http://blog.rebertia.com



More information about the Python-list mailing list