file = open("practice.txt","wt") wt is writing and rt is readingfile.write("a string"\n) \n makes a new linefile.close()data = file.read() Now you can use string methods on datadata.method()import oslistdir(), used as os.listdir()import randomfor i in range(1,10):print random.random()|
Array Access (Selecting a character from a string)
|
O(1)
|
|
Binary Search of a Sorted Collection
|
O(logsub2n)
|
|
Linear Search
|
O(n)
|
|
Better Sorts (Quick Sort, Merge Sort)
|
O(n log n)
|
|
Slower Sorts (Bubble, Insertion, Selection)
|
O(n^2)
|
|
Traveling Salesmen (EX of NP-Complete problem) (Intractable Problem)
|
O(n!)
|
|
Halting Problem - Unsolvable (Proven by Alan Turing, 1936)
|
|
def soundToText(sound,filename): file = open(filename,"wt")for s in getSamples(sound): file.write(str(getSample(s))+"\n") file.close()def encode(msgPic ,original ):for pxl in getPixels(original ):if (getRed(pxl) % 2) == 1:setRed(pxl , getRed(pxl) - 1)for x in range(0, getWidth(original )):for y in range(0, getHeight(original )):msgPxl = getPixel(msgPic ,x,y)origPxl = getPixel(original ,x,y)if (distance(getColor(msgPxl),black) < 100.0):setRed(origPxl , getRed(origPxl )+1)No comments yet.
Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.