方法一:

def duplicated_count(text):
    result=[]
    text=text.lower()
    for i in text:
        if text.count(i) > 1 and i not in result:
            result.append(i)
    return len(result)

 调用函数:

duplicated_count('I love you very much!')

返回:

Python 定义一个函数,检查字符里面是否有重复的字母,并计算重复字母的个数(忽略大小写)

 

方法二:

def dup_counts(s):
    return len([c for c in set(s.lower()) if s.lower().count(c)>1])

调用函数:

dup_counts('I Love you very much!')

返回:

Python 定义一个函数,检查字符里面是否有重复的字母,并计算重复字母的个数(忽略大小写)

相关文章:

  • 2021-08-20
  • 2022-12-23
  • 2022-12-23
  • 2021-08-19
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-26
  • 2021-07-16
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案