code: def humanize_timedelta(td):
      
      secs = int(td.total_seconds())
      hours, secs = divmod(secs, 60 * 60)
      mins, secs = divmod(secs, 60)
      if hours:
          return '%dh %dm' % (hours, mins)
      if mins:
          return '%dm' % mins
      return '%ds' % secs
docs: Pretty-print a timedelta in a human readable format.