I am having problems getting the output of a function to be displayed properly.
This issue seems to be with creating subsets from a string.
my_other_lines = str(other_lines)
print(my_other_lines)
setOfother_lines = set(tuple(i) for i in other_lines)
print(setOfother_lines)
universe = set(range(1, 7))
subsets = [set(setOfother_lines)]
cover = set_cover(universe, subsets, 1)
print(cover)
This is the snippet of code that is supposed to output the results of a set_cover function.
For context, here is the set_cover function
def set_cover(universe, subsets, k):
# Find family of subsets that covers the universal set
k_count = 0
elements = set(e for s in subsets for e in s)
# Checks what subsets cover the universe
if elements != universe:
return None
# Initializing elements covered
covered = set()
cover = []
# Adds subsets with most uncovered points
while (covered != elements) and (k_count < k):
##print(k_count)
subset = max(subsets, key=lambda s: len(s - covered))
cover.append(subset)
covered |= subset
k_count = k_count+1
return cover