Question: Make run time faster. Optimize code # Complete the 'compressword' function below. # # The function is expected to return a STRING. # The function

 Make run time faster. Optimize code \# Complete the 'compressword' function

Make run time faster. Optimize code

\# Complete the 'compressword' function below. \# \# The function is expected to return a STRING. \# The function accepts following parameters: \# 1. STRING word # 2. INTEGER k \# def compressWord (word: str, k: int): \# Write your code here while True: finalChar = False for i in range (len (word) k+1 ): if len(set(word[i:i+k]))==1 : word = word [:i]+word[i+k:] finalChar = True break if not finalchar: break return word

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!