Re: [Tutor] I need to learn more about sorting!

2008-06-24 Thread Kent Johnson
On Tue, Jun 24, 2008 at 1:15 AM, Dick Moores <[EMAIL PROTECTED]> wrote: > At 07:15 PM 6/23/2008, Kent Johnson wrote: >> You should learn how to use list comprehensions: >> alist_tup_elements_reversed.append = [ (x[1], x[0]) for x in alist ] > > Now, that's why I don't use them. They don't make sen

Re: [Tutor] I need to learn more about sorting!

2008-06-23 Thread Dick Moores
At 07:15 PM 6/23/2008, Kent Johnson wrote: On Mon, Jun 23, 2008 at 8:09 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > def sort_tuple_list_by_2nd_elements(alist): > alist.sort Doesn't do anything. > alist_tup_elements_reversed = [] > for x in alist: > alist_tup_elements_rever

Re: [Tutor] I need to learn more about sorting!

2008-06-23 Thread Kent Johnson
On Mon, Jun 23, 2008 at 8:09 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > def sort_tuple_list_by_2nd_elements(alist): > alist.sort Doesn't do anything. > alist_tup_elements_reversed = [] > for x in alist: > alist_tup_elements_reversed.append((x[1], x[0])) You should learn ho

Re: [Tutor] I need to learn more about sorting!

2008-06-23 Thread Dick Moores
After posting I went out, and while out I kept thinking about that function and got a new idea. I didn't realize until I got back that I had completely screwed up my first attempt. Anyway, here's my second, which (I think) does the job for lists of 2-element tuples: ==

Re: [Tutor] I need to learn more about sorting!

2008-06-23 Thread Kent Johnson
On Mon, Jun 23, 2008 at 4:06 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > I needed to sort a list of 2-element tuples by their 2nd elements. We just talked about this: http://thread.gmane.org/gmane.comp.python.tutor/48646/ > I > couldn't see a ready-made function around to do this, so I rolled my

Re: [Tutor] I need to learn more about sorting!

2008-06-23 Thread Jerry Hill
On Mon, Jun 23, 2008 at 4:06 PM, Dick Moores <[EMAIL PROTECTED]> wrote: > I needed to sort a list of 2-element tuples by their 2nd elements. I > couldn't see a ready-made function around to do this, so I rolled my own: ... > colors = [('khaki4', (139, 134, 78)), ('antiquewhite', (250, 235, 215)

[Tutor] I need to learn more about sorting!

2008-06-23 Thread Dick Moores
I needed to sort a list of 2-element tuples by their 2nd elements. I couldn't see a ready-made function around to do this, so I rolled my own:     ==    def sort_tuple_list_by_2nd_elements(alist):     """     Return a list of 2-elemen