第二行不understand,可以拆分1下吗,或者解释也行
def duplicate_count(s):
return len([c for c in set(s.lower()) if s.lower().count(c)>1])
print(duplicate_count('Indivisibilities'))
这是python语言特性:列表解析,它相当于
list = []
for c in set(s.lower()):#将字符串s的所有字母变为小写并生成一个集合,遍历这一集合的字符,每次循环时存为变量c
if s.lower().count(c)>1:#如果小写的字符串s出现过不止一次c字符,就把该字符添加到列表list中
list.append(c)
return len(list) #返回列表list的长度,以统计字符串s中重复出现的字符数量