Counting Duplicates

DESCRIPTION:
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…


This content originally appeared on DEV Community and was authored by Lancelot03

DESCRIPTION:
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

Solution- ###Python

def duplicate_count(text):
    if len(text) == 0:
        return 0
    text=text.lower()
    count=0
    for i in set(text):
        if text.count(i)>1:
            count +=1
    return count


This content originally appeared on DEV Community and was authored by Lancelot03


Print Share Comment Cite Upload Translate Updates
APA

Lancelot03 | Sciencx (2022-07-06T18:21:51+00:00) Counting Duplicates. Retrieved from https://www.scien.cx/2022/07/06/counting-duplicates/

MLA
" » Counting Duplicates." Lancelot03 | Sciencx - Wednesday July 6, 2022, https://www.scien.cx/2022/07/06/counting-duplicates/
HARVARD
Lancelot03 | Sciencx Wednesday July 6, 2022 » Counting Duplicates., viewed ,<https://www.scien.cx/2022/07/06/counting-duplicates/>
VANCOUVER
Lancelot03 | Sciencx - » Counting Duplicates. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/07/06/counting-duplicates/
CHICAGO
" » Counting Duplicates." Lancelot03 | Sciencx - Accessed . https://www.scien.cx/2022/07/06/counting-duplicates/
IEEE
" » Counting Duplicates." Lancelot03 | Sciencx [Online]. Available: https://www.scien.cx/2022/07/06/counting-duplicates/. [Accessed: ]
rf:citation
» Counting Duplicates | Lancelot03 | Sciencx | https://www.scien.cx/2022/07/06/counting-duplicates/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.