index of list of lists

Discussion in 'Python' started by Daniel NL, Apr 17, 2008.

  1. Daniel NL

    Daniel NL Guest

    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?
     
    Daniel NL, Apr 17, 2008
    #1
    1. Advertising

  2. On Thu, 17 Apr 2008 05:15:52 +0300, Daniel NL wrote:

    > 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

    --
    Ivan
     
    Ivan Illarionov, Apr 17, 2008
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Srinath Avadhanula
    Replies:
    7
    Views:
    308
    Dang Griffith
    Dec 23, 2003
  2. =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==

    List of lists of lists of lists...

    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==, May 8, 2006, in forum: Python
    Replies:
    5
    Views:
    432
    =?UTF-8?B?w4FuZ2VsIEd1dGnDqXJyZXogUm9kcsOtZ3Vleg==
    May 15, 2006
  3. Alexzive
    Replies:
    6
    Views:
    621
    Chris Rebert
    Mar 20, 2009
  4. ngoc
    Replies:
    5
    Views:
    194
    Tad McClellan
    May 11, 2006
  5. Tomasz Chmielewski

    sorting index-15, index-9, index-110 "the human way"?

    Tomasz Chmielewski, Mar 4, 2008, in forum: Perl Misc
    Replies:
    4
    Views:
    336
    Tomasz Chmielewski
    Mar 4, 2008
Loading...

Share This Page