Created
January 4, 2020 17:03
-
-
Save kkt-ee/10b65fa2121ed6d1933014d03f630592 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Count the number of Duplicates | |
Write a function that will return the count of distinct case-insensitive alphabetic characters and numeric digits that 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. | |
Example | |
"abcde" -> 0 # no characters repeats more than once | |
"aabbcde" -> 2 # 'a' and 'b' | |
"aabBcde" -> 2 # 'a' occurs twice and 'b' twice (`b` and `B`) | |
"indivisibility" -> 1 # 'i' occurs six times | |
"Indivisibilities" -> 2 # 'i' occurs seven times and 's' occurs twice | |
"aA11" -> 2 # 'a' and '1' | |
"ABBA" -> 2 # 'A' and 'B' each occur twice | |
""" | |
def duplicate_count(text): | |
# Your code goes here | |
text = text.lower() | |
ll = [text.count(c) for c in set(text)] | |
return len( list( filter(lambda x:x>1,ll) ) ) | |
#OR | |
def duplicate_count(s): | |
return len([c for c in set(s.lower()) if s.lower().count(c)>1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment