Menu

[Solved]-Python Data Compression Reduction Number Bits Needed Represent Data Compressing Data Save Q37166923

Python

Data compression is a reduction in the number of bits needed torepresent data. Compressing data can save storage capacity, speedup file transfer, and decrease costs for storage hardware andnetwork bandwidth.

Textspeak or texting language is the abbreviated language andslang commonly used with mobile phone text messaging, or otherInternet-based communication such as email and instant messaging.As one can see, textspeak actually is a form of data compression.It helps in reducing the number of bits and still sends the messageacross.

Write the function compress text(), which takes a twoarguments:• acronyms: a dictionary that maps a phrase to itsacronym

• original text : a string that may or may not contain thephrases found in acronyms

The function takes a string that you need to compress and adictionary that maps phrases to acronyms. You need to loop throughall the keys in the dictionary and, if you find a particular key inthe original text, replace the phrase in the string with the valuestored in the dictionary corresponding to the key. Examples belowwill help to clarify what the result should look like.

The generic way to loop through a dictionary’s keys (e.g., namedmy_dict) looks like this:for key in my_dicts.keys():

… body of loop here …
To find out if a substring appears in a larger string and alsowhere it appears, you can use the find method for strings.

Suppose we want to search for the string phrase in a largerstring called text. The code text.find(phrase)

will return the index of the first character of phrase in text,or -1 if phrase is not inside of text. Some examples of how findworks:

text = ’I love candy and cake and apple pie’phrase = ’candy and cake’index = text.find(phrase) # return value is 7text = ’I love candy and cake and apple pie’phrase = ’ice cream’index = text.find(phrase) # return value is -1

If find returns a value other than -1, this means that thephrase was found, and that phrase can be substituted using theacronym that can be found in the dictionary. The string slicingnotation we learned earlier in the semester, along with stringconcatenation, can solve this problem quite effectively.

Ex.

There will be a common dictionary that we’ll use in the belowexamples:

acronyms = {’laughing out loud’:’LOL’, ’you only live once’ : ’YOLO’, ’i dont know’: ’Idk’, ’direct message’: ’DM’, ’i know right?’ : ’IKR}

Please note that the examples in the driver class are differentfrom the ones provided in the above table.

Function Arguments

Return Value

’I am laughing out loud and I dont know why’’I am LOL and Idk why’’He said you only live once’’He said YOLO’’She direct messaged me. i dont know what to do’’She DMd me. Idk whatto do’’Hi how are you’’Hi how are you’

Expert Answer


Answer to Python Data compression is a reduction in the number of bits needed to represent data. Compressing data can save storage… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *