Question
In python. Write a function substring(string, ch) thatreturn the first substring from string that starts andend with a single character ch. The function shouldreturn None
In python. Write a function substring(string, ch) thatreturn the first substring from string that starts andend with a single character ch. The function shouldreturn None if it can’t find any substring that startsand ends with ch, or return the first substring if more thanone exists.
Note the following:
- capital and a small case of the same letter should be treatedas two different characters.
- the returned substring must at least be of length two
Function header: substring(string, ch)
Input: a string string anda single character ch.
Output: the first (left-most) substringthat starts and ends with thecharacter ch or None if no such substringexists.
Examples:
>>> string = "aaa#bb#zzzz#kkkkkkk#"
>>> ch= "#"
>>> substring(string, ch)
'#bb#'
>>> string = "fff@sss@aaa@ggg@"
>>> ch= "@"
>>> substring(string, ch)
'@sss@'
>>> string = "wwklmonw$%^&www"
>>> ch= "w"
>>> substring(string, ch)
'ww'
>>> string = "qaaa"
>>> ch= "7"
>>> substring(string, ch)
None
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started