Skip to content

Instantly share code, notes, and snippets.

charles gomes charles2588

Block or report user

Report or block charles2588

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View FileOperations.py
def write2file(filename,content,mode):
try:
with open(filename,mode) as f:
f.write(content)
return("Write Successful")
except IOError:
return("IOError-- "+IOError)
def readfromfile(filename):
View LongestSubString.py
def goo_longestsubstring(str,dictionary):
longest=0
longeststr=""
for k,v in dictionary.items():
if v in str:
if longest<len(v):
longest=len(v)
longeststr=v
return longeststr
dictionary={0:"i",1:"charles",2:"am",3:"gomes",4:"substitute",5:"subcharlessubstitute"}
View PythonGenerator.py
#Generator function yields iterator rather than returning value, no function calls or calls on stack thus saving memory
def f(n):
for x in range(n):
yield x**3
for i in f(5):
print(i)
View BinarySearch.py
def binarySearch(arr,searchterm):
pivotpos=int((len(arr)-1)/2)
if pivotpos==0:
return False
if arr[pivotpos]==searchterm:
return arr[pivotpos]
elif arr[pivotpos]>searchterm:
return binarySearch(arr[:pivotpos],searchterm) #search left when searchterm is less than pivot
else:
return binarySearch(arr[pivotpos:],searchterm)#search right when searchterm is greater than pivot
View PrintSpirals.py
def printsprial(m,n):
arr=[]
count=0
for i in range(m):
arr.append([])
for j in range(n):
count+=1
arr[i].append(count)
print(arr)
View C6UJ-0.py
def SortByExampleArray(exampleArr,testArr):
CountDict=dict((el,0) for el in testArr) #initialize dictionary
Result=[] #initialize empty Result array
for x in testArr:
CountDict[x]+=1 #Store count of each number with it's key
for x in exampleArr:
if x in testArr:
for i in range(CountDict[x]):
Result.append(x)
return Result
You can’t perform that action at this time.