Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91892

Re: Please help on this sorted function

Newsgroups comp.lang.python
Date 2015-06-02 13:25 -0700
References <37d9de72-b719-45a0-976c-441fc5898741@googlegroups.com>
Message-ID <70489d38-0848-44c4-9a4c-ba2e2e9aa027@googlegroups.com> (permalink)
Subject Re: Please help on this sorted function
From fl <rxjwg98@gmail.com>

Show all headers | View raw


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'}

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Please help on this sorted function fl <rxjwg98@gmail.com> - 2015-06-02 13:20 -0700
  Re: Please help on this sorted function fl <rxjwg98@gmail.com> - 2015-06-02 13:25 -0700
    Re: Please help on this sorted function Joonas Liik <liik.joonas@gmail.com> - 2015-06-02 23:42 +0300
      Re: Please help on this sorted function Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2015-06-03 18:21 +1000
    Re: Please help on this sorted function Chris Angelico <rosuav@gmail.com> - 2015-06-03 10:01 +1000
  Re: Please help on this sorted function Joonas Liik <liik.joonas@gmail.com> - 2015-06-02 23:32 +0300
  Re: Please help on this sorted function Gary Herron <gherron@digipen.edu> - 2015-06-02 14:00 -0700

csiph-web