title: How to find out if the times are linked in a dictionary?
body: <p>I have a dictionary like this:</p>
  <pre><code>time_values={'5874022': ['00:03:00', '00:08:00', '00:14:00', '07:43:00', '09:33:00', '17:18:00', '23:23:00'], '5873980': ['00:03:00', '03:49:00', '03:53:00', '13:33:00', '23:53:00'], '1548812': ['00:03:00', '12:18:00', '12:23:00'], '646944': ['00:08:00'], '1602678': ['00:08:00', '01:08:00', '01:48:00', '01:53:00', '01:58:00', '20:48:00'], '4124232': ['00:08:00', '00:14:00', '21:28:00', '21:33:00', '21:38:00', '21:43:00'], '5859013': ['00:14:00'], '1555064': ['00:18:00', '00:23:00', '06:08:00', '06:13:00', '07:58:00', '08:03:00', '09:18:00', '19:38:00', '20:08:00'], '645872': ['00:18:00', '00:23:00', '00:28:00', '07:28:00', '07:33:00', '08:38:00', '08:43:00', '08:48:00', '08:53:00', '09:23:00', '09:28:00', '09:33:00', '09:38:00', '09:43:00', '09:48:00', '11:13:00', '11:23:00', '11:28:00', '14:53:00', '14:58:00', '15:03:00', '15:08:00', '15:13:00', '15:18:00', '16:13:00', '16:18:00', '16:23:00', '16:33:00', '16:38:00', '17:08:00', '17:13:00', '17:18:00', '17:23:00', '17:28:00', '17:33:00', '18:23:00', '18:33:00', '18:53:00', '18:58:00'], '5605489': ['00:18:00', '00:23:00', '00:28:00'], '645873': ['00:23:00', '00:28:00', '00:34:00', '00:39:00'], '1575603': ['00:23:00', '00:28:00', '00:34:00', '00:39:00'], '1575605': ['00:23:00', '00:28:00', '00:34:00', '00:39:00', '17:33:00'], '1577854': ['00:23:00', '01:53:00', '21:13:00'], '1575604': ['00:23:00', '00:28:00', '00:34:00', '00:39:00'], '4120380': ['00:23:00', '04:23:00', '05:34:00', '05:38:00', '19:03:00', '19:38:00', '21:13:00'], '5659490': ['00:23:00', '00:28:00', '00:34:00', '00:39:00'], '5659489': ['00:23:00', '00:28:00', '00:34:00', '00:39:00'], '5659488': ['00:23:00', '00:28:00', '00:34:00', '00:39:00', '12:03:00', '21:18:00', '21:23:00', '21:28:00', '21:33:00'], '644457': ['00:23:00', '21:23:00', '21:28:00', '21:33:00', '21:38:00'], '647781': ['00:39:00'], '653461': ['00:39:00', '00:43:00', '03:49:00', '03:53:00', '03:58:00', '04:03:00', '04:08:00', '04:13:00', '15:13:00', '22:38:00', '22:43:00', '22:48:00'], '647782': ['00:39:00'], '2141244': ['00:39:00'], '1576737': ['00:43:00', '02:19:00', '02:23:00', '02:28:00', '02:33:00', '02:38:00', '02:43:00', '14:53:00', '14:58:00', '15:03:00', '16:13:00'], '1567035': ['00:43:00', '03:03:00', '03:08:00', '03:13:00', '03:18:00', '03:23:00'], '1548801': ['00:48:00'], '1556895': ['00:53:00'], '654052': ['00:53:00'], '4139733': ['00:53:00', '00:58:00', '01:03:00'], '642140': ['00:58:00', '03:13:00', '10:13:00', '21:13:00'], '6119951': ['01:03:00', '06:08:00', '06:13:00', '21:28:00', '21:33:00'], '4172822': ['01:03:00', '01:08:00', '01:13:00'], '384766': ['01:08:00', '01:13:00', '07:03:00', '08:58:00', '09:48:00', '14:23:00'], '377420': ['01:18:00', '01:23:00', '01:29:00', '01:33:00', '01:38:00', '01:43:00', '19:18:00'], '647637': ['01:18:00', '01:23:00', '01:29:00', '01:33:00', '19:08:00', '19:13:00'], '3591463': ['01:23:00', '01:29:00', '01:33:00', '01:38:00', '01:43:00', '01:48:00', '09:03:00', '10:08:00', '11:28:00', '11:33:00', '12:53:00', '13:28:00', '15:03:00', '15:28:00', '18:18:00', '18:53:00', '18:58:00', '19:53:00', '20:08:00'], '6201130': ['01:23:00', '01:29:00', '01:33:00']}
  </code></pre>
  <p>I need to find &quot;linked times&quot; (there is 5 or 6 minutes between them) in a segment.
  For example <code>5874022</code> should be look like this:</p>
  <pre><code>time_values={'5874022': ['00:03:00', '00:08:00', '00:14:00'], ['07:43:00'], ['09:33:00'], ['17:18:00', ['23:23:00'], ...}
  </code></pre>
  <p>Edit:
  Here is all my code:</p>
  <pre><code>shaped_timevalues = dict()
  from datetime import datetime
  fmt = '%H:%M:%S'
  newlist= list()
  
  for i,j in time_values.items():
      print('SEGMENTD:',i)
  
      for one in range(len(j)-1):
          one_hour = datetime.strptime(str(j[one]), fmt).strftime(&quot;%H&quot;)
          one_min = datetime.strptime(str(j[one]), fmt).strftime(&quot;%M&quot;)
  
          other_hour = datetime.strptime(str(j[one + 1]), fmt).strftime(&quot;%H&quot;)
          other_min = datetime.strptime(str(j[one + 1]), fmt).strftime(&quot;%M&quot;)
          if one_hour== other_hour and int(one_min) +10&gt;= int(other_min):
              newlist.append(['%s:%s'%(one_hour,one_min),'%s:%s'%(other_hour,other_min)])
              shaped_timevalues.setdefault(i, []).append(['%s:%s'%(one_hour,one_min),'%s:%s'%(other_hour,other_min)])
          else:
              shaped_timevalues.setdefault(i, []).append(['%s:%s' % (one_hour, one_min)])
  print(newlist)
  print(shaped_timevalues)
  </code></pre>
  <p>It takes two values, and sometimes it repeats itself.
  The output comes like this:</p>
  <p><a href="https://i.stack.imgur.com/fevjz.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fevjz.jpg" alt="screenshot" /></a></p>
  <p>Edit2:
  As a result I want to create a new dictionary that in a segment if the values (times) are connected for example in <strong><code>5874022</code></strong>, the <code>'00:03:00'</code>, <code>'00:08:00'</code>, and <code>'00:14:00'</code> times are linked, so they have to be a list in that dictionary.</p>
  <p>As a result, it should be like this:</p>
  <pre><code>time_values = {'5874022': ['00:03:00', '00:08:00', '00:14:00'],
                            ['07:43:00'], ['09:33:00'], ['17:18:00'], ['23:23:00'], ...}
  </code></pre>