check out https://wiki.python.org/moin/HowTo/Sorting as I think we can do this sorting more efficiently using the built in sorting tools.