title: Python- group together instances of a class by attribute
body: <p>I wanted to group together instances of a class based on the value of an attribute.
  Suppose I've got the following class:</p>
  
  <pre><code>class location:
  
      def __init__(self,x_coord,y_coord,text):
          self.x_coord=x_coord
          self.y_coord=y_coord
          self.text=text
  
      def __repr___(self):
          return self.text
  
  mylist=[location(1,0,'Date'),location(5,0,'of'),location(8,0,'Entry'), location(28,0,'Date'),location(29,0,'of'),location(30,0,'Birth') ]
  </code></pre>
  
  <p>I want to group my list of classes if difference in the x_coord attribute is less than 10, so that</p>
  
  <pre><code>mygroupedlist=[['Date','of','Entry'],['Date','of','Birth']]
  </code></pre>
  
  <p>Can someone give me a hint?</p>