#NEWLINE# def preferences_from_user( self , user_id , order_by_id = True ) : #NEWLINE# #INDENT# "\n        Returns\n        -------\n        self.user_preferences :  list [(item_id,preference)]\n         Return user's preferences, ordered by user ID (if order_by_id is True)\n         or by the preference values (if order_by_id is False), as an array.\n\n        " #NEWLINE# preferences = self . preference_values_from_user ( user_id ) #NEWLINE# data = zip ( self . _item_ids , preferences . flatten ( ) ) #NEWLINE# if item_id : #NEWLINE# #INDENT# return [ ( item_id , preference ) for ( item_id , preference ) in data if ( not np . isnan ( preference ) ) ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return sorted ( [ ( item_id , preference ) for ( item_id , preference ) in data if ( not np . isnan ( preference ) ) ] , key = ( lambda item : ( - item [ 1 ] ) ) )