#!/usr/bin/env python # coding: utf-8 # In[7]: import re def replace_words(sentence): # Define a dictionary mapping a single word to a list of words or phrases replacement_map = { # Multiples of ten 'twenty': [], 'thirty': [], 'forty': [], 'fifty': [], 'sixty': [], 'seventy': [], 'eighty': [], 'ninety': [], # Numbers from 11 to 19 'eleven': [], 'twelve': [], 'thirteen': [], 'fourteen': [], 'fifteen': [], 'sixteen': [], 'seventeen': [], 'eighteen': [], 'nineteen': [], # Numbers from 21 to 29 'twenty one': [], 'twenty two': [], 'twenty three': [], 'twenty four': [], 'twenty five': [], 'twenty six': [], 'twenty seven': [], 'twenty eight': [], 'twenty nine': [], # Numbers from 31 to 39 'thirty one': [], 'thirty two': [], 'thirty three': [], 'thirty four': [], 'thirty five': [], 'thirty six': [], 'thirty seven': [], 'thirty eight': [], 'thirty nine': [], # Numbers from 41 to 49 'forty one': [], 'forty two': [], 'forty three': [], 'forty four': [], 'forty five': [], 'forty six': [], 'forty seven': [], 'forty eight': [], 'forty nine': [], # Numbers from 51 to 59 'fifty one': [], 'fifty two': [], 'fifty three': [], 'fifty four': [], 'fifty five': [], 'fifty six': [], 'fifty seven': [], 'fifty eight': [], 'fifty nine': [], # Numbers from 61 to 69 'sixty one': [], 'sixty two': [], 'sixty three': [], 'sixty four': [], 'sixty five': [], 'sixty six': [], 'sixty seven': [], 'sixty eight': [], 'sixty nine': [], # Numbers from 71 to 79 'seventy one': [], 'seventy two': [], 'seventy three': [], 'seventy four': [], 'seventy five': [], 'seventy six': [], 'seventy seven': [], 'seventy eight': [], 'seventy nine': [], # Numbers from 81 to 89 'eighty one': [], 'eighty two': [], 'eighty three': [], 'eighty four': [], 'eighty five': [], 'eighty six': [], 'eighty seven': [], 'eighty eight': [], 'eighty nine': [], # Numbers from 91 to 99 'ninety one': [], 'ninety two': [], 'ninety three': [], 'ninety four': [], 'ninety five': [], 'ninety six': [], 'ninety seven': [], 'ninety eight': [], 'ninety nine': [], # Numbers from one to ten 'seven': [], 'zero': [], 'one': [], 'two': [], 'three': [], 'four': [], 'five': [], 'six': [], 'eight': [], 'nine': [], 'ten': [], # Hundred 'hundred': [], # Thousand 'thousand' : [], # Lakhs 'lakh' : ['lac','lach','laq','lak'], } words = sentence.split() # Split the sentence by spaces # Replace words using the mapping for i, word in enumerate(words): for replacement, patterns in replacement_map.items(): if word in patterns: words[i] = replacement # Replace the word if it's fully matched # Join the processed words back into a sentence return ' '.join(words) # In[ ]: