Jump to content

Sorting 2 0 - In-memory Databases


G+_Darryl Medley
 Share

Recommended Posts

Sorting 2.0 - In-memory Databases

http://pastebin.com/fh3sH7CV

This is something the experienced coders might enjoy. As you know, databases don't store records in sorted order. Instead they use helper files called indexes that just store the sorted field(s) (called keys) and a pointer to the main record with all of the data. There are many advantages to this. Creating multiple indexes essentially allows you to have the data sorted different ways at the same time. Also, you can do things with the keys to improve sorting without affecting the actual data. For example, making the key upper-case gives you a case-insensitive string sort. Using list comprehension it only takes 1 line of code to create an index list for a main list in Python. I've created a simple demo that how this works. It prints a Name, Age, Zipcode list sorted all 3 ways, side-by-side.

http://pastebin.com/fh3sH7CV

Link to comment
Share on other sites

 Share

×
×
  • Create New...