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
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':
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':
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',
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':
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
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
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('@')])
--
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.
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
--
10 matches
Mail list logo