index of list of lists

D

Daniel NL

yes, there's a thread with the same title, but I believe mine is more
appropriate title.
so, as much as I search on the web, read manuals, tutorials, mail-lists
(including this one) I cannot figure it out how to search a string in a
list of lists.
like this one:

someList = [['somestring', 1, 2], ['oneother', 2, 4]]

I want to search "somestring" in someList which is in practice a list
of aprox. 200 lists. (hey, I'm a newbie python programmer, don't judge
me).
is the list.index the wrong approach?
should I use numpy, numarray, something else?
can anyone, be kind and help me with this?
 
I

Ivan Illarionov

yes, there's a thread with the same title, but I believe mine is more
appropriate title.
so, as much as I search on the web, read manuals, tutorials, mail-lists
(including this one) I cannot figure it out how to search a string in a
list of lists.
like this one:

someList = [['somestring', 1, 2], ['oneother', 2, 4]]

I want to search "somestring" in someList which is in practice a list of
aprox. 200 lists. (hey, I'm a newbie python programmer, don't judge me).
is the list.index the wrong approach? should I use numpy, numarray,
something else? can anyone, be kind and help me with this?

You probably need something like this:
[x for x, y, z in someList if x == 'somestring']

or this:
for x, y, z in someList:
if x == 'somestring':
return x
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top