Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using python3 to solve problem Part I: Run-Length Encoding (4 polnts) Run-length encoding is a relatively simple technique for compressing data; if a particular value

image text in transcribedimage text in transcribed

Using python3 to solve problem

Part I: Run-Length Encoding (4 polnts) Run-length encoding is a relatively simple technique for compressing data; if a particular value (or character sequence) appears multiple times in a row, it is only represented once, followed by an integer indicating the number of times it should be repeated. For example, the string "AAAAA" can be compressed to "AS" (5 occurrences of "A"), saving three characters. Complete the expand) function, which takes a single string argument. You may assume that this string is run-length encoded and contains an even number of characters (each pair of characters consists of a character to be printed, fol- lowed by a single (non-zero) digit representing the number of times that character should appear in the expanded string). The function returns a new string that contains the expanded (or decoded) version of its argument. For example, calling expand (" a3b7a2c4") would return the string "aaabbbbbbbaaccc" Hint 1: Use a while loop to solve this problem. Let your loop variable represent your current position (index) within the string, and increment it by 2 after each iteration of the loop, so that it always holds the index of the current character Hint 2: Remember that you can perform multiplication on strings using theoperator. For example, "ab"3 will produce the string "abcabcabc". This will save you from having to use a nested loop to duplicate cach character in the encoded string. As you process the string, multiply the character at the current index i by the (integer) value of the digitat index i+1, then append that string to your result. Examples: unction Call expand ("d305z2y1" expand ("y2e12314p601C5")"yyeZZZ1111pppppr expand ("E2r8A5 9e6F4") xpar ng Part II: Bralding Integers (4 polnts) Given a three-element list of integers that is initially filled with 1s, we can "braid" it by selectively swapping or recombining values lor example, an "odd crossover changes the values l x, y z l to l y, x+y, z and an i even" crossover changes the values Ix, y, z. I to [ x, y+z, y I. These crossovers occur in alternating order: odd, then even, then odd, etc Complete the braid function, which takes a single integer argument representing the "level" of braiding (level 0 means no change, level 1 means a single "odd" crossover turning, nto 1, 2, 1, level 2 means an odd crossover followed by an even crossover, etc.). The function returns the final braided list. You may assume that the function argument is always greater than or equal to 0. Hint: Python's multiple-assignment feature may be useful here. To use it, write the destination variables on the left side, separated by commas; on the right side, write the new values for each variable, again separated by commas a, b -b, a l assign b's old value to a, and a's old value to b Examples: unction Ca braid (0) ra

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David J. Auer David M. Kroenke

13th Edition

B01366W6DS, 978-0133058352

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago