def rank_items(self, userid, user_items, selected_items, recalculate_user=False):
<EOL>if max(selected_items) >= user_items.shape[<NUM_LIT:1>] or min(selected_items) < <NUM_LIT:0>:<EOL><INDENT>raise IndexError("<STR_LIT>")<EOL><DEDENT>liked_vector = user_items[userid]<EOL>recommendations = liked_vector.dot(self.similarity)<EOL>best = sorted(zip(recommendations.indices, recommendations.data), key=lambda x: -x[<NUM_LIT:1>])<EOL>ret = [rec for rec in best if rec[<NUM_LIT:0>] in selected_items]<EOL>for itemid in selected_items:<EOL><INDENT>if itemid not in recommendations.indices:<EOL><INDENT>ret.append((itemid, -<NUM_LIT:1.0>))<EOL><DEDENT><DEDENT>return ret<EOL>
Rank given items for a user and returns sorted item list