[Tutor] list.index() question
Robert Berman
bermanrl at cfl.rr.com
Thu Dec 8 22:13:32 CET 2011
Hi,
Assuming a list similar to this: l1=[['a',1],['b',2],['c',3]] and I want
to get the index of 'c'. A one dimensional list is extremely easy; val =
list.index(value). But how do I get it for a list similar to l1. I have
tried ind = l1[0].index('c') and that tells me 'c' is not in list.
Either my syntax is way off or I am missing the viable solution.
I am reasonably certain I could iterate over l1 until I find either the
value or do not find the value. If that is the only way to go, could
someone share an example of workable code to do that task reasonably well.
Thank you for your assistance.
Robert
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111208/7011377a/attachment.html>
More information about the Tutor
mailing list