题目描述:
# Write a function that will return the count of distinct
# case-insensitive alphabetic characters and numeric digits t
# hat occur more than once in the input string. The input
# string can be assumed to contain only alphabets (both uppercase and lowercase) and numeric digits.
我的解答:
def duplicate_count(text):
t = str(text).lower()
dic_1 = {}
a = 0
for i in t:
dic_1[i] = t.count(i)
for j in dic_1.keys():
if dic_1[j] > 1:
a += 1
return a
更优解法:
def duplicate_count(s):
return len([c for c in set(s.lower()) if s.lower().count(c) > 1])