Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def duplicate_count(text, checkTimes): # RETURNED TYPE = DICTIONARY
- # 1. Find the different letters in the given text (ALL LETTERS WILL BE CONTROLLED LIKE BEING LOWERCASE)
- differentLetters = []
- for ch in text:
- if ch.lower() not in differentLetters:
- differentLetters.append(ch.lower())
- # print("Different letters: " + str(differentLetters))
- # 2. Create a dictionary: Every of the different letters ---> will go to 0 (0 is the initial frequency of appearance)
- # Dictionary will finally have: EACH DIFFERENT LETTER PAIREDWITH HIS FREQUENCY OF APPEARING
- dictionary = {}
- for letter in differentLetters:
- dictionary[letter] = 0
- # print(" Dictionary: " + str(dictionary))
- # 3. I will scan my text to increase the values of the map
- # For every character "ch" in my string = text, I want to repeat the following process
- for ch in text:
- for i in range(0, len(differentLetters)):
- if ch.lower() == differentLetters[i]: # That means I have a hit = (my character ch is equal to the i-th letter of my list differnetLetters)
- # Because of having a hit, letter "ch" is sure in my dictionary. I will increase by 1 its value
- dictionary[ch.lower()] = dictionary.get(ch.lower()) + 1
- break
- counter = 0
- for key, value in dictionary.items():
- if value == checkTimes:
- counter += 1
- return counter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement