def getPossibleNextChars(self, string_so_far): # mHash is the hash of alpha to morse mHash = getHash() morse_so_far = encodeMorse(string_so_far, is_compact=True) return_list = [] # get the string portion from current index on to end of string inspect_string = self.raw_morse[len(morse_so_far):] for alpha in mHash: # if this morse letter is at the beginning of the string... if inspect_string.find(mHash[alpha]) == 0: return_list.append(alpha) return return_list
def encodeMorse(string, is_compact=False): # get the morse code hash table mHash = getHash() returnString = "" # morse code has three spaces between words, one space between characters string = string.replace(" ", " ") # for each char in string, append it to the return string if it is in the morse code hash for i in string.lower(): if i == " ": returnString += " " if i in mHash: returnString += mHash[i] + " " if is_compact: returnString = returnString.replace(" ", "") return returnString.strip()
def encodeMorse(string, is_compact=False): # get the morse code hash table mHash = getHash() returnString = '' # morse code has three spaces between words, one space between characters string = string.replace(" ", " ") # for each char in string, append it to the return string if it is in the morse code hash for i in string.lower(): if i == " ": returnString += " " if i in mHash: returnString += mHash[i] + " " if is_compact: returnString = returnString.replace(" ", "") return returnString.strip()