[Tutor] Another __builtins__.__dict__ question

Bob Gailer ramrom@earthling.net
Mon Dec 9 21:38:02 2002


--=====================_39692404==.ALT
Content-Type: text/plain; charset="us-ascii"; format=flowed

At 07:25 PM 12/9/2002 -0700, Poor Yorick wrote:
>__builtins__.__dict__.keys().sort() returns nothing.

Actually it returns None, as you'd see if you
print __builtins__.__dict__.keys().sort()
which is what sort() always returns.

Another good occasion to read the documentation:
"The sort() and reverse() methods modify the list in place for economy of 
space when sorting or reversing a large list. To remind you that they 
operate by side effect, they don't return the sorted or reversed list."

So try:
keylist = __builtins__.__dict__.keys()
keylist.sort()
print leylist

Bob Gailer
mailto:ramrom@earthling.net
303 442 2625

--=====================_39692404==.ALT
Content-Type: text/html; charset="us-ascii"

<html>
<body>
At 07:25 PM 12/9/2002 -0700, Poor Yorick wrote:<br>
<blockquote type=cite class=cite cite>__builtins__.__dict__.keys().sort()
returns nothing.</blockquote><br>
Actually it returns None, as you'd see if you <br>
print __builtins__.__dict__.keys().sort()<br>
which is what sort() always returns.<br><br>
Another good occasion to read the documentation:<br>
&quot;The <tt>sort()</tt> and <tt>reverse()</tt> methods modify the list
in place for economy of space when sorting or reversing a large list. To
remind you that they operate by side effect, they don't return the sorted
or reversed list.&quot;<br><br>
So try:<br>
keylist = __builtins__.__dict__.keys()<br>
keylist.sort()<br>
print leylist<br>
<x-sigsep><p></x-sigsep>
Bob Gailer<br>
<a href="mailto:ramrom@earthling.net" eudora="autourl">mailto:ramrom@earthling.net</a><br>
303 442 2625<br>
</body>
</html>

--=====================_39692404==.ALT--