[Tutor] List sorting issues

Luke Paireepinart rabidpoobear at gmail.com
Tue Mar 29 00:24:15 CEST 2011


Sort returns none because it changes your list in-place. Print your list out after calling sort and you should see the new one.

-----------------------------
Sent from a mobile device. Apologies for brevity and top-posting.
-----------------------------

On Mar 28, 2011, at 11:53 AM, Eric Stevens <element.effect at gmail.com> wrote:

> I am currently designing an address book program, and am trying to design a method for organizing the keys (which are the names of the entries) for displaying purposes. I have created a list by doing sortedKeys = self.addbook.keys() {the self.addbook refers to a dictionary in a custom class}, and then i try to do a sortedKeys.sort() but never get an alphabetical list of the keys. All i get is 'None'. I know that a 'list.sort()' returns a None value but all of the tutorials I see show this giving an alphabetized list.
> 
>  I have also tried doing a 'sorted(self.addbook)' which gives me a list but not alphabetized. The dictionary keys I am using are 'Eric', 'Kyle', and 'dfd' and they always appear in that order when i use the sorted() feature (obviously not alphabetized).
> 
>  Could you please let me know what I am doing wrong or let me know of another way to alphabetize an iterable object. Thank you.
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor


More information about the Tutor mailing list