about sort and dictionary

OKB (not okblacke) brenNOSPAMbarn at NObrenSPAMbarn.net
Tue Nov 22 16:26:25 EST 2005


Fredrik Lundh wrote:

> bonono at gmail.com wrote:
> 
>> > so what would an entry-level Python programmer expect from this
>> > piece of code?
>> >
>> >     for item in a.reverse():
>> >         print item
>> >     for item in a.reverse():
>> >         print item
>> >
>> I would expect it to first print a in reverse then a as it was.
>>
>> a=[1,2,3]
>>
>> I expect it to print
>>
>> 3
>> 2
>> 1
>> 1
>> 2
>> 3
> 
> really?  wouldn't
> 
>     3
>     2
>     1
>     3
>     2
>     1
> 
> make a lot more sense ?

    	Yes.  The unintuitive thing is that the list is sorted in place at 
all.

-- 
--OKB (not okblacke)
Brendan Barnwell
"Do not follow where the path may lead.  Go, instead, where there is
no path, and leave a trail."
	--author unknown



More information about the Python-list mailing list