Dec-16-2021, 12:42 AM
(This post was last modified: Dec-16-2021, 12:43 AM by NeedHelpPython.)
Problem : 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 (
"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
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): new_list = [] list_to_set = set(new_list) for i in text: new_list.append(i) if len(new_list) != len(list_to_set): print("Difference") return new_list test = duplicate_count("665")Im kind of stuck how to solve this in python. I think my thought process is correct but im not executing it correctly.. What I did is first I make a empty list and then I convert it into the set and try to compare the differences from there. I see all the solutions to the problem using a dictionary when I searched up the problem but I want it to be completed using a set/list. Can someone help me on this? I know my code isn't correct