我有以下两个清单.
清单1
(a,b,h,g,e,t,w,x)
清单二
((a,yellow),(h,green),(t,red),(w,teal))
我想返回以下内容
((a,yellow),(b,null),(h,green),(e,null),(t,red),(w,teal),(x,null))
for x in List_1:
for y in list_2:
if x == y
print y
else print x, "null"
有关如何做到这一点的任何想法?
谢谢
最佳答案 放手一搏:
a = ('a', 'b', 'h', 'g', 'e', 't', 'w', 'x')
b = (('a', 'yellow'), ('h', 'green'), ('t', 'red'), ('w', 'teal'))
B = dict(b)
print [(x, B.get(x, 'null')) for x in a]