原因是因为在代码中使用了'type'这个变量名,而'type'是Python中的保留关键字,因此会发生类型错误。解决方法是更改变量名。
示例代码:
def min_del_anagram(s1, s2): freq = [0] * 26 for c in s1: freq[ord(c) - 97] += 1 for c in s2: freq[ord(c) - 97] -= 1 count = 0 for f in freq: count += abs(f) return count
type = "abcd" print(min_del_anagram("listen","silent"))
def min_del_anagram(s1, s2): freq = [0] * 26 for c in s1: freq[ord(c) - 97] += 1 for c in s2: freq[ord(c) - 97] -= 1 count = 0 for f in freq: count += abs(f) return count
type_value = "abcd" print(min_del_anagram("listen","silent"))
上一篇:按agg函数进行分组和筛选
下一篇:Anagular8如何使用服务