Please help on this sorted function

fl rxjwg98 at gmail.com
Tue Jun 2 16:25:12 EDT 2015


On Tuesday, June 2, 2015 at 1:20:40 PM UTC-7, fl wrote:
> Hi,
> 
> I try to learn sorted(). With the tutorial example:
> 
> 
> 
> 
> >>> ff=sorted({1: 'D', 2: 'B', 3: 'B', 4: 'E', 5: 'A'})
> >>> ff
> [1, 2, 3, 4, 5]
> 
> 
> 
> I don't see what sorted does in this dictionary, i.e. the sequence of 
> 1..5 is unchanged. Could you explain it to me?
> 
> 
> Thanks,

Excuse me. After a small modification, it can see the effect.


>>> ff=sorted({1: 'D', 2: 'B', 5: 'B', 4: 'E', 3: 'A'})
>>> ff
[1, 2, 3, 4, 5]


I am still new to Python. How to get the sorted dictionary output:

{1: 'D', 2: 'B', 3: 'A', 4: 'E', 5: 'B'}



More information about the Python-list mailing list