我想有以下几点:比较两个字符串的相似性在Python
Input: ("a#c","abc")
Output: True
Input:("a#c","abd")
Desired Output: False
Real Output: True
所以该函数返回true,如果两个字符串的长度相同,如果他们通过#字符,它表示只有不同为随机字符。 如果不是,我希望它返回False。
该功能应该改变什么?
def checkSolution(problem, solution):
if len(problem) != len(solution):
return False
if len(problem) == len(solution):
for i, c in zip(problem, solution):
if i != c:
return False
if i == c or "#" == c:
return True
print (checkSolution("a#c","abc"))
print (checkSolution("a#c","abd"))
出了什么问题?首先是缩进;) –
也许,很好的答案已经在这里:http://stackoverflow.com/questions/1471153/string-similarity-metrics-in-python –
注意审稿人:虽然罗马提供的链接有很多更好的方法比较字符串的相似性,它实际上并没有回答为什么他当前的解决方案不起作用的问题 – Foon