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
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
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
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:
==
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
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)
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