Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 2 [30 pts] : a) [10 pts] Define a function called three_sub_str that takes in as input a string and returns a string made

image text in transcribedimage text in transcribed
Question 2 [30 pts] : a) [10 pts] Define a function called three_sub_str that takes in as input a string and returns a string made of the first 3 and the last 3 characters from the input. If the string length is less than 3, then return the string Not Possible . Examples: 1. Input: 'watermelon'; Output: watlon 2. Input: 'try'; Output: trytry 3. Input: 'as'; Output: Not Possible [6] : #INSERT YOUR ANSWER HERE. b) [10 pts] Define a function five_reverse that takes as input a string and returns the reverse of the string if its length is a multiple of 5; else returns the original string. Examples: 1. Input: 'GreenApple'; Output: 'elppAneerG' 2. Input: 'RedApple'; Output: 'RedApple' [7] : #INSERT YOUR ANSWER HERE.c) [10 pts] Define a function count_char that takes in as input a string and a boolean value and returns a dictionary with each character in the string as key and the count of the number of times the character appeared in the string as value. If the boolean value is True , it returns the dictionary with only the most frequent character; else, it returns the entire dictionary. Examples: 1. Input: 'apple', False; Output: {'a': 1, 'p': 2, 'l': '1', 'e': '1'} 2. Input: 'apple', True; Output: {'p': 2} [8 ] : #INSERT YOUR ANSWER HERE. BONUS [10 pts] Define a function called min_sub_str that takes two string arguments ( S and T ) and returns the first possible substring (traversing from left) containing all the elements of T . For example: given S = 'xBXXAXXCXXAx(XxBXXXAx(xBxxxxxBxCx' and T = "ABC" , return "BxxAxxC" [9] : #INSERT YOUR ANSWER HERE

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

Step: 3

blur-text-image

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

Calculus For Scientists And Engineers Early Transcendentals

Authors: William L Briggs, Bernard Gillett, Bill L Briggs, Lyle Cochran

1st Edition

0321849213, 9780321849212

More Books

Students also viewed these Mathematics questions

Question

2 What participation techniques are used?

Answered: 1 week ago