def remove_itself_and_enemies(lists, l): """ >>> x = [[1,2,3],[3,4],[4,5,6],[6,7,8,9]] >>> GreedyMaxCover.remove_itself_and_enemies(x,[1,2,3]) == [[4,5,6],[6,7,8,9]] True """ f, e = MaxCover.find_friend_enemy(lists, l) result = [] for i in lists: if i == l or i in e: continue result.append(i) return result
def get_list_with_maximum_friends(lists): """ >>> x = [[1,2,3],[3,4],[4,5,6],[6,7,8,9]] >>> GreedyMaxCover.get_list_with_maximum_friends(x) == [1,2,3] True """ result = {} for i, l in enumerate(lists): friend, enemy = MaxCover.find_friend_enemy(lists, l) f = MaxCover.length_of_total_elements(friend) e = MaxCover.length_of_total_elements(enemy) result[i] = f - e # print result r = sorted(result.iteritems(), key=operator.itemgetter(1), reverse=True) # print r return lists[r[0][0]]