[Tutor] Sort pointers -

Liam Clarke cyresse at gmail.com
Thu Nov 25 06:15:29 CET 2004


Thanks Jacob, so many ways to do this...

oh, and kia ora - literally means 'be healthy', from the Maori, used
as a greeting these days.

http://en.wikipedia.org/wiki/New_Zealand_English#M.26.23257.3Bori_influence


On Wed, 24 Nov 2004 23:56:31 -0500, Jacob S. <keridee at jayco.net> wrote:
> If your curious and you want the output described, this would work.
> 
> ----------------------------------------------------------------------------
> --
> miscPeople= {'James Bond' : '007' , 'Enid Blyton' : '005' , 'Enid Blyton
> also' : '006' , 'Captain Planet' : '000' }
> miscPeople.keys().sort()
> for x in miscPeople.keys():
>     print x,miscPeople[x]
> ----------------------------------------------------------------------------
> --
> Oh, and what does Kia ora mean, and what language is it in?
> 
> Jacob Schmidt
> 
> 
> 
> 
> > Kia ora,
> >
> > Just exploring the wonderful world of dictionaries, and I'm trying to
> > comprehend the sort() method, because as I found, dictionaries are not
> > sorted.
> >
> > So, I've got a dictionary, miscPeople= {'James Bond' : '007' , 'Enid
> > Blyton' : '005' , 'Enid Blyton also' : '006' , 'Captain Planet' :
> > '000' }
> >
> > (Okay, so that's a sample dictionary)
> >
> > So, if I wanted to sort by alphabetical key i.e. (first names here)
> >
> > for name, numerical in miscPeopledict.sorted() (pseudo code):
> >    print name, numerical
> >
> > Captain Planet 000
> > Enid Blyton 005
> > Enid Blyton also 006
> > James Bond 007
> >
> > or conversely, to sort by value in some manner
> >
> > for name, numerical in miscPeopledict.sorted.reverse()
> >
> > James Bond 007
> > Enid Blyton also 006
> > Enid Blyton 005
> > Captain Planet 000
> >
> > That's just an example of output. I'm not too hung up on the output at
> > the moment, just sort().
> >
> > It says to use a comparison function...
> >
> > And I have no idea how to work that.
> >
> > ??? Very confused. I've tried searching for info, there's some very
> > complex ways out there to sort data, usually with proper first names
> > (Schwartzian transformations...), but I can't seem to find the simple.
> >
> > Could anyone post some useful links for my education?
> >
> > Much appreciated.
> >
> > Liam Clarke
> >
> >
> > --
> > 'There is only one basic human right, and that is to do as you damn well
> please.
> > And with it comes the only basic human duty, to take the consequences.
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
> 
> 


-- 
'There is only one basic human right, and that is to do as you damn well please.
And with it comes the only basic human duty, to take the consequences.


More information about the Tutor mailing list