3 回答
TA贡献1801条经验 获得超16个赞
可以定义自己的字符串比较函数,将字符一一遍历并进行比较,只要金色字符不是“Don't Care”值即可:
def myStringCompare(golden, measured, dont_care="X"):
return (
(len(golden) == len(measured)) and
all(g == m for g, m in zip(golden, measured) if g != dont_care)
)
然后在列表理解中使用这个函数:
print([myStringCompare(a, b) for a, b in zip(Golden, Measured)])
#[True, True, True, True, True, True, True, True, True]
TA贡献1847条经验 获得超7个赞
您可以使用
[all(char1 == 'X' or char1 == char2 for char1, char2 in zip(str1, str2)) for str1, str2 in zip(list1, list2)]
TA贡献1111条经验 获得超0个赞
我已经能够提出以下列表理解:
result_list = [
all(
[
symbol == b[list_index][symbol_index]
for symbol_index, symbol in enumerate(item)
if symbol != "X"
]
)
for list_index, item in enumerate(a)
]
> [True, True, True, True, True, True, True, True, True]
添加回答
举报