<jupyter_start><jupyter_text>Assignment 2 --- a.Build a dictionary with abbreviations as keys and associated texts as values. Read the provided text file ***abbreviations.txt,*** each line of which contains an abbreviation and the associated text with it. (You should display the list lines to see what a string of this list looks like).<jupyter_code># Main Variable that will contain the list
aDict = {}

# Setup the file and read all the data from it, then save it to 'sfList'
with open('abbreviations.txt', 'rt') as sf:
    sfList = sf.readlines()
    
# Loop through sfList and finish setting up the aDict (Abbreviations Dictionary)
for sfw in sfList:
    i = sfList.index(sfw)
    sfw = sfw.replace('\n', '')
    sfw = sfw.split(':')
    aDict[sfw[0]] = sfw[1]
    
# Print the dictionary
print(aDict)<jupyter_output>{'r': 'are', 'y': 'why', 'u': 'you', 'ttyl': 'talk to you later', 'l8': 'late', 'brb': 'be right back', 'lol': 'laughing out loud', 'bbl': 'be back later', 'tldr': "too long; didn't read", 'rofl': 'rolling on floor laughing', 'gtg': 'got to go', 'cya': 'see you', 'cuzz': 'because', 'bff': 'best friend forever', 'idk': "I don't know", 'sup': "what's up?", 'omg': 'oh my gosh', 'nbd': 'no big deal', 'tisnf': 'this is not fair', 'nw': 'no way!', 'rus': 'are you serious?', 'myob': 'mind your own business', 'njoy': 'enjoy', 'nter': 'enter', '1ce': 'once', 'aka': 'also known as', 'afk': 'away from keyboard', 'jk': 'just kidding', 'asap': 'as soon as possible', 'app': 'application', 'atm': 'at the moment', 'b4': 'before', 'fyi': 'for your information', 'bday': 'birthday', 'k': 'okay', 'msg': 'message', 'np': 'no problem', 'pic': 'picture', 'plz': 'please', 'sry': 'sorry', 'dunno': "don't know", 'wut': 'what', 'wuts': "what's"}<jupyter_text>--- b.Translate a message.Split the message into "words". If a "word" is in the dictionary, replace it by the associated text. Otherwise simply copy the "word" to the translation.<jupyter_code># Get User's message which is to be converted into full form
# userInput = 'y r u l8' # Test input string
userInput = input('Enter your Message: ')

# Initiate the Variable in which the full form of the message will be given as output
message = ''

# Check each word in the user's message as to if it is an abbreviation or not and append 
# the resulting word into the 'message' variable
for word in userInput.split():
    try:
        message += aDict[word] + ' '
    except:
        message += word + ' '
        
# Finally print out the full form version of the message
print("Full Message:", message)<jupyter_output>Enter your Message: y r u l8
Full Message: why are you late
{'fraction_non_alphanumeric': 0.15871212121212122, 'fraction_numerical': 0.0030303030303030303, 'mean_word_length': 4.389795918367347, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '666589', 'license': 'MIT', 'n_tokens_mistral': 876, 'n_tokens_neox': 843, 'n_words': 369, 'path': '2020_12_05_Assignment/Assignment_2_Solution/Assignment 2.ipynb', 'repo_name': 'MePerplexeus/AI-Practice-Assignments', 'size': '2640'}