Created
March 25, 2011 21:33
-
-
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".
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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