Insertion sort in python

Insertion sort, is an efficient algorithm for sorting a small number of elements. Insertion sort works the way many people sort a hand of playing cards. We start with an empty left hand and the cards face down on the table. We then remove one card at a time from the table and insert it into the correct position in the left hand. To find the correct position for a card, we compare it with each of the cards already in the hand, from right to left.
Read more →

Read GAE Admin Backups fromLevelDB format and export GAE Entities using bulkloader

Google datastore is pretty awesome when one needs a quick no-sql data storage. However recently I have experienced a problem in exporting my GAE Datastore as csv and in certain cases as a line delimited Json file. Its not very hard to do so and perhaps the easiest way to handle such thing is to write an export handler in you web app, however, there are alternative ways which I have highlighted below.
Read more →

Bubble-sort in python

Read more →

longest palindrome in a string

Read more →

print two-dimensional array in spiral order

So I saw this problem in a book today about printing a 2d matrix in spiral order Here are two solutions to it Solution one. def printSpiralTL(m,x1,y1,x2,y2): for i in range(x1,x2): print m[y1][i] for j in range(y1+1,y2+1): print m[j][x2-1] if x2-x1 > 0: printSpiralBL(m, x1, y1 + 1, x2-1, y2) def printSpiralBL(m,x1,y1,x2,y2): for i in range(x2-1,x1-1,-1): print m[y2][i] for j in range(y2-1,y1-1,-1): print m[j][x1] if x2-x1 > 0: printSpiralTL(m, x1+1, y1, x2, y2-1) m = [ [1, 2, 3, 4], [5, 6, 7, 8], [9, 0, 1, 2], [3, 4, 5, 6], [7, 8, 9, 1] ] Output:
Read more →