"The function can be implemented using a for loop. Given an input string s. Initialize two empty strings to append the digits and the substrings found in the input string, i.e. dig='' and res=''. Iterate over each character in the string and check if it is a digit using the method isdigit(). If it is a digit append it to the digits string i.e. dig += ele, else append it to the substring string res i.e. res += ele. After the loop terminates, append the digits string to the substring string res, i.e. res += dig.