Re: Sorting a list of dictionaries by dictionary key

2006-05-04 Thread Alex Martelli
Tim Chase <[EMAIL PROTECTED]> wrote: > > assuming that DateTime returns something that compares correctly, you can > > do something like: > > > > def sortkey(item): > > return item.get("from_datetime") > > > > data.sort(key=sortkey) > > > > (assuming Python 2.4 or later) > > Bu

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread Eric Deveaud
bruno at modulix wrote: > Eric Deveaud wrote: > (snip) > > > > sort can take a comparaison function. > > The problem with it is that it may slow down things a lot... point taken. I have to purge my mind from the other programing languages I practice. ;-) Eric -- http://mail.python

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread Fredrik Lundh
Nico Grubert wrote: > > assuming that DateTime returns something that compares correctly, you can > > do something like: > > > > def sortkey(item): > > return item.get("from_datetime") > > > > data.sort(key=sortkey) > > > > (assuming Python 2.4 or later) > > Thank you very much, Fr

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread bruno at modulix
Eric Deveaud wrote: (snip) > > sort can take a comparaison function. The problem with it is that it may slow down things a lot... -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for p in '[EMAIL PROTECTED]'.split('@')])" -- http://mail.python.org/ma

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread Nico Grubert
> assuming that DateTime returns something that compares correctly, you can > do something like: > > def sortkey(item): > return item.get("from_datetime") > > data.sort(key=sortkey) > > (assuming Python 2.4 or later) Thank you very much, Frederik. Unfortunately, I can only use P

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread Tim Chase
> assuming that DateTime returns something that compares correctly, you can > do something like: > > def sortkey(item): > return item.get("from_datetime") > > data.sort(key=sortkey) > > (assuming Python 2.4 or later) Building on Fredrik's solution, for 2.3 (or earlier?), you ca

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread Eric Deveaud
Nico Grubert wrote: > Hi there, > > I am looking for a way to sort a list containing dictionaries. > > This is my example list: > [{'Title': 'ABC', 'from_datetime': DateTime('2006/04/25 12:45:00 > GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18 > 12:45:00 GMT+2')}, {'Titl

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread bruno at modulix
Nico Grubert wrote: > Hi there, > > I am looking for a way to sort a list containing dictionaries. > > This is my example list: > [{'Title': 'ABC', 'from_datetime': DateTime('2006/04/25 12:45:00 > GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18 > 12:45:00 GMT+2')}, {'Title': 'GHI

Re: Sorting a list of dictionaries by dictionary key

2006-05-03 Thread Fredrik Lundh
Nico Grubert wrote: > I am looking for a way to sort a list containing dictionaries. > > This is my example list: > [{'Title': 'ABC', 'from_datetime': DateTime('2006/04/25 12:45:00 > GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18 > 12:45:00 GMT+2')}, {'Title': 'GHI', 'from_dateti

Sorting a list of dictionaries by dictionary key

2006-05-03 Thread Nico Grubert
Hi there, I am looking for a way to sort a list containing dictionaries. This is my example list: [{'Title': 'ABC', 'from_datetime': DateTime('2006/04/25 12:45:00 GMT+2')}, {'Title': 'DEF', 'from_datetime': DateTime('2006/04/18 12:45:00 GMT+2')}, {'Title': 'GHI', 'from_datetime': DateTime('200