code: def convert_time(time):
      
      split_time = time.split()
      try:
          # Get rid of period in a.m./p.m.
          am_pm = split_time[1].replace('.', '')
          time_str = '{0} {1}'.format(split_time[0], am_pm)
      except IndexError:
          return time
      try:
          time_obj = datetime.strptime(time_str, '%I:%M %p')
      except ValueError:
          time_obj = datetime.strptime(time_str, '%I %p')
  
      return time_obj.strftime('%H:%M %p')
docs: Convert a time string into 24-hour time.