title: Convert AM,PM to 24 in a nested list using python
body: <p>I have a nested list with AM,PM time format. I want to convert these to 24 hours format. I wrote a code that convert the times to 24 but the result is not true. What is wrong in my code?</p>
  <pre><code>mylist =  [
      ['x', '06:00 - 09:30 AM - 10:30 AM , 02:00 PM - 05:00 PM - 09:00 PM'],
      ['y', '07:30 AM - 02:30 PM, 07:30 AM , 02:30 PM, 07:30 AM - 01:30 PM']
  ]
  
  correctResult= [['x', '06:00 - 09:30 AM - 10:30 AM - 14:00 PM - 17:00 PM - 21:00 PM'],
      ['y', '07:30 AM - 14:30 PM, 07:30 AM - 14:30 PM, 07:30 AM - 13:30 PM']]
  
  myresult = [
  ['x', ['06:00', '09:30', '10:30', '14:00', '17:00', '21:00']], ['x', ['06:00', '09:30', '10:30', '14:00', '17:00', '21:00']], ['x', ['06:00', '09:30', '10:30', '14:00', '17:00', '21:00']], ['x', ['06:00', '09:30', '10:30', '14:00', '17:00', '21:00']], ['x', ['06:00', '09:30', '10:30', '14:00', '17:00', '21:00']], ['x', ['06:00', '09:30', '10:30', '14:00', '17:00', '21:00']], ['y', ['07:30', '02:30 PM, 07:30 AM', '02:30 PM, 07:30 AM', '13:30']], ['y', ['07:30', '02:30 PM, 07:30 AM', '02:30 PM, 07:30 AM', '13:30']], ['y', ['07:30', '02:30 PM, 07:30 AM', '02:30 PM, 07:30 AM', '13:30']], ['y', ['07:30', '02:30 PM, 07:30 AM', '02:30 PM, 07:30 AM', '13:30']]
  ]
  </code></pre>
  <p>The code is as below:</p>
  <pre><code>def time24(timepmam):
      from datetime import datetime
  
      in_time = datetime.strptime(timepmam, &quot;%I:%M %p&quot;)
      out_time = datetime.strftime(in_time, &quot;%H:%M&quot;)
      return out_time
  
  result = []
  
  for x in mylist:
    res = x[0]
  
    ss = []
    for y in x[1].split(' - '):
        # print(y)
      if len(y) &gt; 5 and len(y)&lt;9:
            print(y)
            t = time24(y)
            ss.append(t)
      else:
          ss.append(y)
      s = ' '.join(ss)
      result.append([res, ss])
  
  print(result)
  </code></pre>