Monthly Archives: July 2010

Generators in Python.

The following examples are using Python 2.x but now after seeing Python 3.x released I’m interested in generators larger role in Python. Generators remind me of accumulators: generators accumulate a comprehensive result that you can add to with calls to yield. Take the following as an example. def cubes(c): for i in range(c): yield i [...]

Posted in Programming | Tagged | Leave a comment

Generate list of random integers in Python.

I use this for testing and that is about it. import random def randomArr(length, max): arr = [] for i in range(0, length): arr.append(random.randint(0, max)) return arr

Posted in Programming | Tagged , , | Leave a comment

Insertion sort in Python.

I’m losing faith in my programming skills today, so I’ve decided to re-implement sorting functions. Each day I’ll try to decrease the complexity of the algorithms, but, this day being the first, I’ll give you a quadratic insertion sort. This is an insertion sort, right, or is it shell sort? Heh… def insertionSort(arr): for i [...]

Posted in Programming | Tagged , , | Leave a comment