<p>The list <code>sort()</code> method is a modifier function that returns <code>None</code>.</p>

<p>So if I want to iterate through all of the keys in a dictionary I cannot do:</p>

<pre><code>for k in somedictionary.keys().sort():
    dosomething()
</code></pre>

<p>Instead, I must:</p>

<pre><code>keys = somedictionary.keys()
keys.sort()
for k in keys:
    dosomething()
</code></pre>

<p>Is there a pretty way to iterate through these keys in sorted order without having to break it up in to multiple steps?</p>

Can I answer my own question?
I have just discovered the handy function "sorted" which does exactly what I was looking for.
```
for k in sorted(somedictionary.keys()):
    dosomething()
```
It shows up in
Python 2.5 dictionary 2 key sort