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) Building on Fredrik's

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':

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_datetime':

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 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')}, {'Title':

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 can use

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 Python

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('@')]) --

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, Frederik.

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 --