我有一个列表列表(listA),我有另一个单独的列表(listB).我试图根据我在testing12函数中完成的类型和位置来检查listB是否匹配listA中的任何列表.我的问题是我能做些什么才能使if语句给我一个整体评价,即真或假.如果有一个或多个匹配则为True,如果根本没有匹配则为False.
listA = [[3,"alpha"], [7, 8], ["hat", "bat"]]
listB = [5,5]
def testing12(x,y):
result = map(type, x) == map(type, y)
return result
for n in lists:
if testing12(list,n) == True:
print "True"
else:
print "False"
Run Code Online (Sandbox Code Playgroud)
if any(testing12(list, n) for n in lists):
print("at least one matched")
Run Code Online (Sandbox Code Playgroud)
要么:
if all(testing12(list, n) for n in lists):
print("All lists matched")
Run Code Online (Sandbox Code Playgroud)