title: python : sorting a dictionary using datetime as key
body: <p>I am trying to read from a log file which has a timestamp with milliseconds as follows
  and then inserting into a dictionary based on 'st_time' as key.</p>
  
  <pre><code>st_time = datetime.strptime(t_str[0],"%d/%b/%Y %H:%M:%S.%f")
  final_dict[st_time] = line
  for key in sorted(final_dict.iterkeys()):
      print "%s : %s" %(key,final_dict[key])
  </code></pre>
  
  <p>But I get this error below </p>
  
  <pre><code>for key in sorted(final.iterkeys()):
  
  
  TypeError: can't compare datetime.datetime to tuple
  </code></pre>
  
  <p>Sample:
  An entry from log file</p>
  
  <pre><code>Jul  1 03:27:12 syslog: [m_java]**[ 1/Jul/2013 03:27:12.818]**[j:[SessionThread &lt;]^Iat com/avc/abc/magr/service/find.something(abc/1235/locator/abc;Ljava/lang/String;)Labc/abc/abcd/abcd;(bytecode:7)
  
  t_str[0] --&gt; ['29/Jun/2013 01:16:06.149']
  
  st_time --&gt; 2013-06-29 01:16:06.149000
  </code></pre>
  
  <p>Thanks for any help!</p>