Python: Find item in multidimensional list -


i have list of lists, snippet of below:

x_attrib = []

self.x_attrib.append(["is_virtual", false, 'virtual', 'flag']) self.x_attrib.append(["x_pos", none, 'pos/x', 'attrib']) self.x_attrib.append(["y_pos", none, 'pos/y', 'attrib']) 

i want make functional returns index of item @ first position (i.e. want pass "x_pos" function, , have return 1).

how can this?

if understand correctly, need this:

def find_it(key):    index, sublist in enumerate(lists):        if sublist[0] == key:             return index 

having said code looks solving more general problem incorrectly. i.e. list bad idea. without better idea of doing cannot certain.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -