This file contains 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 qsort(data): | |
if data==[]: | |
return data | |
pivot=data[0] | |
less=qsort([x for x in data[1:] if x<pivot]) | |
great=qsort([x for x in data[1:] if x>=pivot]) | |
return less+[pivot]+great |
This file contains 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 qsort2(data): | |
if data==[]: | |
return data | |
mid=len(data)/2 | |
pivot=data.pop(mid) | |
less=qsort2(filter(lambda x:x<pivot,data)) | |
great=qsort2(filter(lambda x:x>=pivot,data)) | |
return less+[pivot]+great |
This file contains 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
class MyProperty(object): | |
def __init__(self, name): | |
self.__name = name | |
@property | |
def xname(self): | |
return self.__name | |
@xname.setter | |
def xname(self, val): |
This file contains 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
class MyPropertyValidation(object): | |
def __init__(self): | |
self.__age = None | |
@property | |
def age(self): | |
if not self.__age: | |
raise ValueError("Age is None and needs to be set first.") | |
return self.__age |
This file contains 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
class MyPropertyValidation(object): | |
def __init__(self): | |
self.__age = None | |
@property | |
def age(self): | |
if not self.__age: | |
raise ValueError("Age is None and needs to be set first.") | |
return self.__age |
This file contains 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
class MyAbstractProperty(object): | |
__metaclass__ = abc.ABCMeta | |
@abc.abstractproperty | |
def xname(self): pass | |
class MyAbstractPropertySubclass(MyAbstractProperty): | |
@property |
This file contains 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
class MyFinalProperty(object): | |
@property | |
def name(self): | |
return "John" |
This file contains 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
class MyOtherProperty(object): | |
def __init__(self, name): | |
self.name = name | |
def getXName(self): | |
return self.name | |
def setXName(self, val): | |
self.name = val |
This file contains 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
@memoize | |
def add_values( a, b ): | |
return a+b |
This file contains 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 decorator(func): | |
""" | |
:param func: | |
:return: func result after calling it with 1 | |
""" | |
return func(1) | |
#Below statement is equal to decorator( decoratee ) | |
@decorator | |
def decoratee(number): |
OlderNewer