Tutorial by Examples

Basic Idea The notation used when describing the speed of your Python program is called Big-O notation. Let's say you have a function: def list_check(to_check, the_list): for item in the_list: if to_check == item: return True return False This is a simple function ...
Operations : Average Case (assumes parameters are randomly generated) Append : O(1) Copy : O(n) Del slice : O(n) Delete item : O(n) Insert : O(n) Get item : O(1) Set item : O(1) Iteration : O(n) Get slice : O(k) Set slice : O(n + k) Extend : O(k) Sort : O(n log n) Multiply : O(nk) x in...
A deque is a double-ended queue. class Deque: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def addFront(self, item): self.items.append(item) def addRear(self, item): self.items.insert(0,item) def removeFront(self): return self....
Operation : Average Case (assumes parameters generated randomly) : Worst case x in s : O(1) Difference s - t : O(len(s)) Intersection s&t : O(min(len(s), len(t))) : O(len(s) * len(t) Multiple intersection s1&s2&s3&...&sn : : (n-1) * O(l) where l is max(len(s1),...,len(sn)) s...
There are certain principles that apply to optimization in any computer language, and Python is no exception. Don't optimize as you go: Write your program without regard to possible optimizations, concentrating instead on making sure that the code is clean, correct, and understandable. If it's too...

Page 1 of 1