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
import math | |
class A(object): | |
cursur = 0.0 | |
def __init__(self,x,y): | |
self.x = x | |
self.y = y | |
def move_forward(self,x,y): | |
x+=1 | |
y+=1 | |
A.cursur += math.sqrt(x**2 + y**2) |
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 json import loads,dumps | |
def Unicodify(func): | |
βββ | |
Checkes in the incoming data-types and returns unicode values | |
Intended only for strings and JSON Objects | |
βββ | |
def wrapper(obj): | |
if isinstance(obj, str): | |
return loads(obj) | |
elif isinstance(obj, dict): |
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 sample(a,*args,**kwargs): | |
print βa is {}β.format(a) | |
print β*args is a tuple {}β.format(args) | |
print β**kwargs is a dictionary {}β.format(kwargs) | |
>>> sample(1,2,3,4,name=βrahulβ,age=26) | |
a is 1 | |
*args is a tuple (2, 3, 4) | |
**kwargs is a dictionary {βageβ: 26, βnameβ: βrahulβ} |
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 example_function(arg1,arg2,arg3,*args): | |
print βarg1 is {0}β.format(arg1) | |
print βarg2 is {0}β.format(arg2) | |
print βarg3 is {0}β.format(arg3) | |
print β*arg is {0}β.format(args) | |
>>> example_function(1,2,3,4,5,6,7,8,9,10) | |
arg1 is 1 | |
arg2 is 2 | |
arg3 is 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
#Its in python 3 | |
def LinearSearch(my_item,my_list): | |
found = False | |
position = 0 | |
while position < len(my_list) and not found: | |
if my_list[position] == my_item: | |
found = True | |
position += 1 | |
return found |
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 BinarySearch(my_item,my_list): | |
found = False | |
bottom = 0 | |
top = len(my_list)-1 | |
while bottom<=top and not found: | |
middle = (bottom+top)//2 | |
if my_list[middle] == my_item: | |
found = True | |
elif my_list[middle] < my_item: | |
bottom = middle + 1 |
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
class mimic_range: | |
def __init__(self,maximum): | |
self.maximum = maximum | |
def __iter__(self): | |
self.current = 0 | |
return self | |
def next(self): | |
num = self.current |
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 double(function): | |
def wrapper(*args,**kwargs): | |
return 2 * function(*args,**kwargs) | |
return wrapper | |
@double | |
def adder(x,y): | |
return x + y | |
print adder(1,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 multiply(by = None): | |
def multiply_real_decorator(function): | |
def wrapper(*args,**kwargs): | |
return by * function(*args,**kwargs) | |
return wrapper | |
return multiply_real_decorator | |
@multiply(by = 3) | |
def adder(a,b): | |
return a + b |
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 duplicate(function): | |
def wrapper(*args,**kwargs): | |
return 2*function(*args,**kwargs) | |
return wrapper | |
def formatting(lowerscase = False): | |
def formatting_real(function): | |
def wrapper(*args, **kwargs): | |
if lowerscase: |
OlderNewer