Hi I have been reading stuff like:

http://wiki.python.org/moin/SortingListsOfDictionaries

I want to sort a list of dictionaries (alphanumeric values) by
multiple keys (achieved with code below). However I would like to
customise the comparator to put empty objects last.

eg:

def orderBasedOnDepartment(items):
    return sorted(items, key=lambda
items:(items['department'],items['suburb'],items['state'],items['distanceNm']))

for instance if the dictionary containing key: department = None
then I would like it placed after everything else instead of before.

Changed from:

None
A
Aa
Ab
C
D

To:

A
Aa
Ab
C
D
None

Any help would be appreciated so I can have a day off for christmas.

-sam

--

You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.


Reply via email to