G+_Darryl Medley Posted May 14, 2014 Share Posted May 14, 2014 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 More sharing options...
G+_Darryl Medley Posted May 16, 2014 Author Share Posted May 16, 2014 For anyone interested this is the "user program" that was featured on episode 17, May 15th. Link to comment Share on other sites More sharing options...
Recommended Posts