[Tutor] Fastest find in 2 2D lists with else statement

Kale Good kale at kalegood.com
Fri Mar 20 13:22:03 CET 2015


Hello all,
I'm new to python and a bit of a weekend-warrior programmer (guitar 
teacher by trade), so there are plenty of computer sciencey concepts 
that I haven't grasped yet, and I think I'm bumping up against those now.

Read from separate csv files, I have something like

     a=[['bass',9],['eagle',36],['human',68]]
     b=[['bass','fish'],['eagle','bird'],['dog',land']]
     c=[[1,'fish','water'],[2, 'mammal','land'],[3,'bird','air']]

What I want is to return where each animal lives. What I've been able to 
glisten from the manuals and stack overflow is:

for i in range(len(a)):

         for x in range(len(b)):
           if a in b[x][1]:
              clss = (b[x][0])
occurrence  w/ else statement
         for y in range(len(c)):
            if clss in c[y][1]:
               place = (c[y][2])

         a[i].append(place)

a)I'd like to have an else statement; if a match isn't found in b, 
prompt the user for one of the values in c[:][0]. (no need to print the 
list c; the user will have that available elsewhere)

b)Is there a faster way to do this? List a has ~300 elements, while list 
b has ~45000, so I'm curious if I can make it faster.
     -I only need to find the first match, so it seems a next statement 
would do the trick. However, I can't figure out how to use next for 
finding in two 2d arrays.
    -From my understanding, for this use, b needs to be a list. However, 
each line is unique, so it could be a set if necessary.

Thanks in advance.

Best,
Kale
-- 
------------------------------------------------------------------------
Kale Good: Guitar Instructor ♫
phillyguitarlessons.com <http://phillyguitarlessons.com>
phone: (215)260-5383

  * 4705 Baltimore Ave, Phila, PA 19143 :Mailing & Lessons
  * 1867 Frankford Ave. Phila, PA 19125 :Lessons

Google+ <https://plus.google.com/b/105422331794047992190/>
Facebook <http://facebook.com/KaleGoodGuitarStudio>
Read my article "The Seven Secrets to Six String Success 
<http://www.guitarnoise.com/lesson/seven-secrets-to-six-string-success/>" at 
GuitarNoise.com <http://guitarnoise.com>
Leading the Journey from No-Skills-Guitarist to Talented Musician!



More information about the Tutor mailing list