This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /usr/bin/env python | |
| # All right reserved. Distributed Under BSD Lisence | |
| __author__="Arun.K.R <[email protected]>" | |
| __date__ ="$May 11, 2011 6:23:17 PM$" | |
| import os, time | |
| from random import choice | |
| WIDTH = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def compare(x, y): | |
| return y < x | |
| def cmp_to_key(mycmp, col, covert_to_proper_datatype): | |
| class K(object): | |
| class K(object): | |
| def __init__(self, obj, *args): | |
| self.obj = obj | |
| def __lt__(self, other): | |
| return mycmp(covert_to_proper_datatype(self.obj[col]), covert_to_proper_datatype(other.obj[col])) == False |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cmp_to_key(col, covert_to_proper_datatype, cmpr = (lambda x, y: x < y)): | |
| class K(object): | |
| def __init__(self, obj, *args): | |
| self.obj = obj | |
| def __lt__(self, other): | |
| return cpmr(covert_to_proper_datatype(self.obj[col]), covert_to_proper_datatype(other.obj[col])) == True | |
| return K |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def cmp_to_key(col, covert_to_proper_datatype): | |
| #Discrad this approch, once we have an option to sort via webmethods, sorting by DB engine is more efficient than doing it ourselves. | |
| class K(object): | |
| def __init__(self, obj, *args): | |
| self.obj = obj | |
| def __lt__(self, other): | |
| return covert_to_proper_datatype(self.obj[col]) < covert_to_proper_datatype(other.obj[col]) | |
| return K |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| mapping_functions = { | |
| 'str_lower' : lambda x: x.lower(), | |
| 'date_mdY' : lambda x: datetime.strptime(x, "%m/%d/%Y"), | |
| 'ssn' : lambda x: int(x.replace('-', '')) | |
| 'int' : lambda x: int(x) | |
| 'dom' : lambda x: int(m.parseString(x).childNodes[0].childNodes[0].nodeValue) | |
| } | |
| mapping_tbl = [] | |
| mapping_tbl.insert(0, mapping_functions['dom']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sorted([[5, 'Man', 1], [2, 'Arun', 6], [4, 'Dummy', 6], [1, 'Naveen', 3], [3, 'Bajsd', 7]], key=lambda x: str(x[1]).lower()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| sorted([[5, 'Man', 1], [2, 'Arun', 6], [4, 'Dummy', 6], [1, 'Naveen', 3], [3, 'Bajsd', 7]], key=lambda x: str(x[1]).lower()) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from datetime import datetime | |
| import xml.dom.minidom as m | |
| def cmp_to_key(col, covert_to_proper_datatype): | |
| class K(object): | |
| def __init__(self, obj, *args): | |
| self.obj = obj | |
| def __lt__(self, other): | |
| return covert_to_proper_datatype(self.obj[col]) < covert_to_proper_datatype(other.obj[col]) | |
| return K |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct User{ | |
| char name[45]; | |
| int age; | |
| float height; | |
| }usr; | |
| usr.name = "Someone"; | |
| usr.age = 31; | |
| ur.height = 6.1; |
OlderNewer