Question

For Phton language 3. You are to create a decoder program that takes a tweet as...

For Phton language 3.

You are to create a decoder program that takes a tweet as input and turns it into an English sentence. A tweet will contain common acronyms and abbreviations, and your program will need to have a way to decode them (dictionary).

For example) “lol” => “laughing out loud”, “brb” => “be right back”
Provided is a file with common tweet abbreviations and associated meanings, your program is to use this

csv file (tweet_decoder.csv) to create its dictionary.

Start by creating a framework for the program that contains a dictionary with a few abbreviations

such as
decoder = { “brb” : ”be right back”, ”b4” : ”before” ...}

Ask for a user to input a tweet.

Lookup abbreviations within the tweet, decode and replace them.

Print out the decoded string.

Offer the option to run again.

Your program will need to open up the “tweet_decoder.csv” file. Make sure that this file is

copied into the same directory where your python file is saved.

Review slide 16 from week 12 (part1, Record example 2) as a reference.

Each line of the CSV file represents a key and a value pair – These needs to be added to the

dictionary.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# pastebin link for code:https://pastebin.com/bFF6txL4

word_dict = {}

with open("tweet_decoder.csv", "r") as fh:
    for line in fh:
        (abbr, meaning) = line.split(",", 1)
        print(abbr, meaning)
        word_dict[abbr] = meaning.strip()
        word_dict[abbr.lower()] = meaning.strip()

def tweet_decoder(tweet):
    tweet_split = tweet.split()
    result_tweet = []
    for tweet in tweet_split:
        if tweet in word_dict:
            result_tweet.append(word_dict[tweet])
        else:
            result_tweet.append(tweet)
    return " ".join(result_tweet)

tweet = input("Enter a tweet: ")
tweet = tweet_decoder(tweet)

print("Decoded tweet: " + tweet)

'''
File used
brb,be right back
b4, before
lol, laghing out loud
'''

# Sample run
# Enter a tweet: This is an example tweet brb to complete it b4 you die lol
# Decoded tweet: This is an example tweet be right back to complete it before you die laghing out loud

Add a comment
Know the answer?
Add Answer to:
For Phton language 3. You are to create a decoder program that takes a tweet as...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Java program Program: Grade Stats In this program you will create a utility to calculate and...

    Java program Program: Grade Stats In this program you will create a utility to calculate and display various statistics about the grades of a class. In particular, you will read a CSV file (comma separated value) that stores the grades for a class, and then print out various statistics, either for the whole class, individual assignments, or individual students Things you will learn Robustly parsing simple text files Defining your own objects and using them in a program Handling multiple...

  • In this lab you will write a spell check program. The program has two input files:...

    In this lab you will write a spell check program. The program has two input files: one is the dictionary (a list of valid words) and the other is the document to be spellchecked. The program will read in the words for the dictionary, then will read the document and check whether each word is found in the dictionary. If not, the user will be prompted to leave the word as is or type in a replacement word and add...

  • Exercise 3) Creating a QT program to search for Customer Phone Number : Create a text...

    Exercise 3) Creating a QT program to search for Customer Phone Number : Create a text file (customer.txt) and put names and phone numbers into it. each name has to have its own phone number right under it. In the QT window, the user has to enter a name and the program prints the phone number related to it. NB: If the user input a name that doesn't exist, the program should print an error message. Text file example: QT...

  • Please do the following project in C++ programming language. You can use a bag to create...

    Please do the following project in C++ programming language. You can use a bag to create a spell checker. The bag serves as a dictionary and contains a collection of correctly of correctly spelled workds. To see whether a word is spelled correctly, you see whether it is contained in the dictionary. Use this scheme to create a spell checker for the words in an external file. To simplify your task, restrict your dictionary to a manageable size. The dictionary...

  • Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create...

    Help needed with Python 3: Dictionaries and Sets. The problem is one that asks the user to create a completed program that prompts the user for the name of a data file, and reads the contents of that data file, then creates variables in a form suitable for computing the answer to some questions. The format should be in the same manner as the attached .py file. All subsequent assignment details (.py and .csv files) can be found at this...

  • In C++ Having heard you have gotten really good at programming, your friend has come to...

    In C++ Having heard you have gotten really good at programming, your friend has come to ask for your help with a simple task. She would like you to implement a program to encrypt the messages she exchanges with her friends. The idea is very simple. Every letter of the alphabet will be substituted with some other letter according to a given key pattern like the one below. "abcdefghijklmnopqrstuvwxyz" "doxrhvauspntbcmqlfgwijezky" // key pattern For example, every 'a' will become a...

  • Solve the Sudoku game using the inputs available online. You can create your own input file...

    Solve the Sudoku game using the inputs available online. You can create your own input file as long is it is in the same format as the sample files given. Lookup online the rules for Sudoku if you are uncertain. You will be required to use concepts we have gone over in the class. Do not use techniques we have not discussed! Items that are required: Read in game board from a .txt file. Write out solution to game board...

  • Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher...

    Language: C Write an encoder and a decoder for a modified "book cipher." A book cipher uses a document or book as the cipher key, and the cipher itself uses numbers that reference the words within the text. For example, one of the Beale ciphers used an edition of The Declaration of Independence as the cipher key. The cipher you will write will use a pair of numbers corresponding to each letter in the text. The first number denotes the...

  • Need help with code in C# Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results. The application should allow the user to enter...

    Need help with code in C# Create an application that reads a file named Accounts.txt. Your application should load the file and display back the results. The application should allow the user to enter additional entries and save them back to the same file. The CSV file should contain the following fields: AccountName, InvoiceDate, DueDate, AmountDue If the CSV file contains invalid data you want to inform the user which row contained bad data. Below is an example of what...

  • Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like...

    Create an algorithm to count the number of 1’s in a 32-bit number. Implement the program in a high level language like C or Java. It does not need to run for me, but the code should be included in a text document called FirstnameLastnameHLA3.txt along with your assignment submission. Implement the program in MIPSzy Assembly language. Use the high level code as comments to the right of the Assembly code as the textbook does. If you write that MIPSzy...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT