<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def strfdelta(tdelta, fmt):
 """ Used to format `datetime.timedelta` objects. Works just like `strftime` param tdelta: Time duration which is an instance of datetime.timedelta param fmt: The pattern to format the timedelta with rtype: str """

    substitutes = dict()
    hours, rem = divmod(tdelta.total_seconds(), 3600)
    minutes, seconds = divmod(rem, 60)

    substitutes["H"] = '{:02d}'.format(int(hours))
    substitutes["M"] = '{:02d}'.format(int(minutes))
    substitutes["S"] = '{:02d}'.format(int(seconds))
    return DeltaTemplate(fmt).substitute(**substitutes)