'Get list of images with similar words.'

def candidates_from_histogram(self, imwords):

    words = imwords.nonzero()[0]
    candidates = []
    for word in words:
        c = self.candidates_from_word(word)
        candidates += c
    tmp = [(w, candidates.count(w)) for w in set(candidates)]
    tmp.sort(cmp=(lambda x, y: cmp(x[1], y[1])))
    tmp.reverse()
    return [w[0] for w in tmp]
