Skip to content

Instantly share code, notes, and snippets.

@sgammon
Created March 25, 2011 21:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sgammon/887680 to your computer and use it in GitHub Desktop.
Save sgammon/887680 to your computer and use it in GitHub Desktop.
Write an algorithm to sort these objects in ascending order, by the property "score".
import random
import hashlib
class SearchResult(object):
key = None
score = None
def __init__(self):
self.score = round(random.random(),2)*5
h = hashlib.md5()
h.update(str(self.score))
self.key = h.hexdigest()
def __str__(self):
return 'SearchResult "'+str(self.key)+'" ::: VALUE: "'+str(self.score)+'".'
### Generate some objects
objects = [SearchResult() for i in xrange(0, 25)]
### Fill this output array! Sort by search result score. Must output a list of keys ordered by score (asc).
output = []
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment