title: Applying lambda function to datetime
body: <p>I am using the following code to find clusters with difference &lt;=1 in a list </p>
  
  <pre><code>from itertools import groupby
  from operator import itemgetter
  data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
  for k, g in groupby(enumerate(data), lambda (i, x): (i-x)):
      print map(itemgetter(1), g)
  </code></pre>
  
  <p>If however I change the <code>data</code> to be an array of datetime to find cluster of datetimes which are only 1 hour apart, it fails.</p>
  
  <p>I am trying the following:</p>
  
  <pre><code>&gt;&gt;&gt; data
  array([datetime.datetime(2016, 10, 1, 8, 0),
         datetime.datetime(2016, 10, 1, 9, 0),
         datetime.datetime(2016, 10, 1, 10, 0), ...,
         datetime.datetime(2019, 1, 3, 9, 0),
         datetime.datetime(2019, 1, 3, 10, 0),
         datetime.datetime(2019, 1, 3, 11, 0)], dtype=object)
  
      from itertools import groupby
      from operator import itemgetter
      data = [ 1, 4,5,6, 10, 15,16,17,18, 22, 25,26,27,28]
      for k, g in groupby(enumerate(data), lambda (i, x): (i-x).total_seconds()/3600):
          print map(itemgetter(1), g)
  </code></pre>
  
  <p>The error is:</p>
  
  <pre><code>    for k, g in groupby(enumerate(data), lambda (i, x): int((i-x).total_seconds()/3600)):
  TypeError: unsupported operand type(s) for -: 'int' and 'datetime.datetime'
  </code></pre>
  
  <p>There are lot of solutions on the web but I want to apply this particular one for learning.</p>