Question

PYTHON ONLY PLEASE

Q6 Encoder / Decoder 1 Point Design and implement encoder and decoder functions that perform run length compression of string

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

******************************************************************************************
Please Upvote the answer as it matters to me a lot :)
*****************************************************************************************
As per HomeworkLib expert answering guidelines,Experts are supposed to answer only certain number of questions/sub-parts in a post.Please raise the remaining as a new question as per HomeworkLib guidelines.
******************************************************************************************

def encoder(s):
a=[]
i=1
count=1
while(i<len(s)):
count=1
while (i<len(s)) and (s[i]==s[i-1]):
count+=1
i+=1
a.append([s[i-1],count])
i+=1
return a
def decoder(a):
ans= ""
for x in a:
ans= ans+ x[0]*x[1]
return ans
s= input("Enter a string to be encoded: ")

print("The encoded string is :",encoder(s))
print("The decoded string is :",decoder(encoder(s)))

Shortcuts S Reset Copy : -14 va Python 3 1. def encoder(s): a=[] i=1 count=1 while(i<len(s)): count=1 while (i<len(s)) and (s

Add a comment
Know the answer?
Add Answer to:
PYTHON ONLY PLEASE Q6 Encoder / Decoder 1 Point Design and implement encoder and decoder functions...
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
  • PLEASE CODE IN PYTHON Run-length encoding is a simple compression scheme best used when a data-set...

    PLEASE CODE IN PYTHON Run-length encoding is a simple compression scheme best used when a data-set consists primarily of numerous, long runs of repeated characters. For example, AAAAAAAAAA is a run of 10 A’s. We could encode this run using a notation like *A10, where the * is a special flag character that indicates a run, A is the symbol in the run, and 10 is the length of the run. As another example, the string KKKKKKKKKKKKKBCCDDDDDDDDDDDDDDDKKKKKMNUUUGGGGG would be encoded...

  • 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...

  • In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of...

    In PYTHON! Exercise 3: Lists and Functions In this exercise we will explore the use of lists and functions with multiple inputs and multiple outputs. Your task is to implement the separate_and_sort function. This function takes two input parameters: 1. A list containing strings and integers in any order. 2. An optional integer parameter size which controls how many items in the list the function will process. If the length of the list is smaller than the value of size,...

  • A combination circuit is specified by the following Boolean functions listed below. h(a, b, c) = b,c' + a'c Implement the circuit with a 3x8 decoder. Provide truth table and drawing the l...

    A combination circuit is specified by the following Boolean functions listed below. h(a, b, c) = b,c' + a'c Implement the circuit with a 3x8 decoder. Provide truth table and drawing the logic/circuit diagram. Use the block diagram for the decoder provided in Figure A4 in supplements. Please label the inputs and outputs clearly. Note: use single 3x8 decoder Question 2 (15 points] A priority encoder is an encoder circuit that includes the Truth Table of a priority function. The...

  • In python please. Write a program that reads whitespace delimited strings (words) and an integer (freq)....

    In python please. Write a program that reads whitespace delimited strings (words) and an integer (freq). Then, the program outputs the strings from words that have a frequency equal to freq in a case insensitive manner. Your specific task is to write a function wordsOfFreqency(words, freq), which will return a list of strings (in the order in which they appear in the original list) that have a frequency same as the function parameter freq. The parameter words to the function...

  • Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a...

    Please write the code in a text editor and explain thank you! 1. LINKED-LIST: Implement a function that finds if a given value is present in a linked-list. The function should look for the first occurrence of the value and return a true if the value is present or false if it is not present in the list. Your code should work on a linked-list of any size including an empty list. Your solution must be RECURSIVE. Non-recursive solutions will...

  • Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You...

    Programs 1. String Utilities In this exercise you will implement several utility functions involving strings. You will place all of your function prototypes in a header file named string utils.h and all of your function definitions in a source file named string utils.c. You should implement your own main test driver program to test your functions, but you need not hand it in. a. void addChar(char *str, char c, int n) - this function should add a char c at...

  • on python Design a function that can generate a histogram of characters in a string with...

    on python Design a function that can generate a histogram of characters in a string with the function prototype: histogram(string) It takes a string as the input parameter and returns a Python dictionary. Then design a function with the following prototype. print_hist_asc(histogram) It takes a histogram generated from your histogram function and print the histogram according to the frequency in the ascending order. Example input: “aaaaabbbbcccdde” Example output: e 1 d 2 c 3 b 4 a 5

  • In python, please help me fill in these functions given their limitations. Please use for loops....

    In python, please help me fill in these functions given their limitations. Please use for loops. def palindrome(x): """ For a given string, determine if the string is a palindrome. (The same forward and back) Input: String of any size (including empty) Return: Boolean (True if palindrome, False otherwise) Limitation: You must use a loop. Only function allowed to be used is len (if needed). Cannot use "in" besides "for var in container" """ pass def getCount(char, strng): """ Get...

  • Stacks and Java 1. Using Java design and implement a stack on an array. Implement the...

    Stacks and Java 1. Using Java design and implement a stack on an array. Implement the following operations: push, pop, top, size, isEmpty. Make sure that your program checks whether the stack is full in the push operation, and whether the stack is empty in the pop operation. None of the built-in classes/methods/functions of Java can be used and must be user implemented. Practical application 1: Arithmetic operations. (a) Design an algorithm that takes a string, which represents an arithmetic...

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