There are two lists, we find the data.

Given:

v = [465,641,638,637,644,645,648,689,709,1022,1032,1065,1067] g = [(705L,), (637L,), (638L,),] 

I receive:

 res = [x for x in g if x[0] in v] print res [(637L,), (638L,)] 

Bypassing the sequence, the options are interested in how to simplify the code block

 x = [] for j1 in res: #тут передаем данные в MySQL res2 = dbHandle.execute(sql.format(j1[0],'mul_add)).fetchall() if res2: x.append(res2) 

    1 answer 1

    The variant of two generators is possible, which will make less, of course, only the number of lines.

    The expression itself becomes more complicated:

    x = [dbHandle.execute(sql.format(j1[0], mul_add)).fetchall() for j1 in res] x = [i for i in x if i]