Question: def myAppend ( str , ch ) : # Return a new string that is like str but with character ch added at the end
def myAppendstr ch: # Return a new string that is like str but with character ch added at the end return str ch def myCountstr ch: # Return the number of times character ch appears in str count for char in str: if char ch: count return count def myExtendstr str: # Return a new string that contains the elements of str followed by the elements of str return str str def myMinstr: # Return the character in str with the lowest ASCII code. if lenstr: printEmpty string: no min value" return None minchar str for char in str: if char minchar: minchar char return minchar def myInsertstr i ch: # Return a new string like str except that ch has been inserted at the ith position. if i lenstr: printInvalid index" return None return str:i ch stri: def myPopstr i: # Return two results: a new string with the ith element removed, and the value that was removed. if i lenstr: printInvalid index" return str None removedchar stri newstr str:i stri: return newstr removedchar def myFindstr ch: # Return the index of the first leftmost occurrence of ch in str if any. Return if ch does not occur in str for i in rangelenstr: if stri ch: return i return def myRFindstr ch: # Return the index of the last rightmost occurrence of ch in str if any. Return if ch does not occur in str for i in rangelenstr: if stri ch: return i return def myRemovestr ch: # Return a new string with the first occurrence of ch removed. If there is none, return str index strfindch if index : return str:index strindex: return str def myRemoveAllstr ch: # Return a new string with all occurrences of ch removed. If there are none, return str return strreplacech def myReversestr: # Return a new string like str but with the characters in the reverse order. return str:: # Test cases s "abcd" s "efgh" printmyAppendse # 'abcde' printmyCountse # printmyCountsa # printmyCountabcabca # printmyExtends s # 'abcdefgh' printmyMin # Empty string: no min value printmyMinzqralm # a printmyMinHello World!" # printmyInsertabcd # 'dabc' printmyInsertabcd # 'abdc' printmyInsertabcd # Invalid index printmyPopabcd # acdb printmyPopabcd # bcda printmyPopabcd # Invalid index printmyFindabcdabcda # printmyFindabcdabcdc # printmyFindabcdabcdf # printmyRFindabcdabcdd # printmyRFindabcdabcde # printmyRemoveabcdabcda # 'bcdabcd' printmyRemoveabcdabcdx # 'abcdabcd' printmyRemoveabcdabcdd # 'abcabcd' printmyRemoveAllabcabcabcaa # bcbcbc printmyReverseabcd # 'dcba' printmyReverse #
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
