Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THIS IS A PYTHON PROBLEM ON CODESTEPBYSTEP.COM: http://www.codestepbystep.com/problem/view/python/strings/reverse_chunks Write a function named reverse_chunks that accepts a string s and integer k as parameters and returns

THIS IS A PYTHON PROBLEM ON CODESTEPBYSTEP.COM: http://www.codestepbystep.com/problem/view/python/strings/reverse_chunks

Write a function named reverse_chunks that accepts a string s and integer k as parameters and returns a new string that reverses the relative order of every k characters of s. For example, the call of reverse_chunks("MehranSahami", 3) should view the string in groups of 3 characters at a time, reversing "Meh" into "he_m", and "ran" into "nar", and so on, returning a result of "he_mnarha_sima".

If the string's length is not an exact multiple of k, the last chunk of fewer-than-k characters at the end of the string should be left in its original order. For example, if the call is reverse_chunks("MartyStepp", 4), the first chunk "Mart" becomes "tra_m" and the second chunk "y_ste" becomes "et_sy". The last two characters, "pp", are fewer than 4, so they are left as-is. So the result returned should be "tra_met_sypp".

You may assume that the value passed for k will be a positive integer.

Constraints: You should not create any data structures such as arrays. But you may create as many strings as you like, and you may use as many simple variables (such as ints) as you like.

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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

=+from: a) a MNEs perspective? and b) the HRM managers perspective?

Answered: 1 week ago