title: Sort a dictionary by values that are instance attributes
body: <p>I am currently working on a program written in Python 2.6.6. It uses a dictionary that looks like:</p>
  
  <pre><code>{ 'somekeystring': someobject("a name", 1, 3),
  'anotherkey': someobject("another name", 2, 2),
  'keythree': someobject("third name", 3, 1) }
  </code></pre>
  
  <p>The object has some attributes like:</p>
  
  <pre><code>name
  startOrder
  stopOrder
  </code></pre>
  
  <p>What I am trying to accomplish is to get the dictionary sorted. Once by someobject.startOrder, once by someobject.stopOrder.</p>
  
  <p>I have tried</p>
  
  <pre><code>sortedByStartOrder = sorted(mydict.iteritems(), key=lambda x: x[1].startOrder)
  </code></pre>
  
  <p>but this does not seem to work. The list items are sorted in the same order, no matter if I use startOrder or stopOrder in the example above.</p>
  
  <p>Any hints?</p>