Skip to content

Instantly share code, notes, and snippets.

@kra3
Created September 19, 2011 19:30
Show Gist options
  • Save kra3/1227345 to your computer and use it in GitHub Desktop.
Save kra3/1227345 to your computer and use it in GitHub Desktop.
mapped dict for sorting
mapping_tbl = []
mapping_tbl.insert(0, lambda x: int(m.parseString(x).childNodes[0].childNodes[0].nodeValue))
mapping_tbl.insert(1, lambda x: x.lower())
mapping_tbl.insert(2, lambda x: x.lower())
mapping_tbl.insert(3, lambda x: int(x))
mapping_tbl.insert(4, lambda x: datetime.strptime(x, "%m/%d/%Y"))
mapping_tbl.insert(5, lambda x: int(x.replace('-', '')))
mapping_tbl.insert(6, lambda x: datetime.strptime(x, "%m/%d/%Y"))
mapping_tbl.insert(7, lambda x: datetime.strptime(x, "%m/%d/%Y"))
mapping_tbl.insert(8, lambda x: x.lower())
mapping_tbl.insert(9, lambda x: x.lower())
search_data = sorted(search_data, key=cmp_to_key(column_to_sort, mapping_tbl[column_to_sort]), reverse = (sort_dir != "asc"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment