Python pymysql将两个不同查询的结果合并到
我做过这样的事情:Python pymysql将两个不同查询的结果合并到,python,pymysql,Python,Pymysql,我做过这样的事情: sql_query1=... sql_query2=... cur.execute(sql_query1,(actorId1,actorId2)) results1=cur.fetchall() cur.execute(sql_query2,(actorId1,actorId2)) results2=cur.fetchall() nested_tuple_list1=[] for result in results1: nested_tuple_list1.a
sql_query1=...
sql_query2=...
cur.execute(sql_query1,(actorId1,actorId2))
results1=cur.fetchall()
cur.execute(sql_query2,(actorId1,actorId2))
results2=cur.fetchall()
nested_tuple_list1=[]
for result in results1:
nested_tuple_list1.append(result)
return(nested_tuple_list1)
nested_tuple_list2=[]
for result in results2:
nested_tuple_list2.append(result)
return(nested_tuple_list2)
我想得到两个查询的共同结果。你知道我能做什么吗
我需要的一个例子:
jim | tim | a jim | dan | b
dan | mo | b dan | mo | b
jim | dan | c
我想得到:
dan | mo | b
不太清楚您想要实现什么,但如果您使用列表,最简单的方法是:
intersection=[nested\u tuple\u list1中值的值(如果nested\u tuple\u list2中的值)]
假设您将元组作为一个整体而不是其中的元素进行匹配,则上述内容也适用于列表中的元组。比如说
a=[(1, 2), (18, 3), (9, 8), (11, 83)]
b=[(4, 3), (8, 47), (42, 77), (1, 2), (3, 18)]
intersection=[value for value in a if value in b]
我得到的结果是:
[(1, 2)]
如果您想比较列表元素中的元组,这会有点复杂,但也是可行的 我编辑过,所以它会更清楚,但我想你已经涵盖了我