[Tutor] A dictionary question
Phil
phillor9 at gmail.com
Mon Nov 15 02:30:40 EST 2021
Thank you once again for taking the time to look at this.
I've refined the requirements from my previous question. What I need is
to check for the existence of a pair of sets from the set_list in the
row list of sets twice and not in any other set. {4,6} in the first row
list of sets fulfills the requirement and there are no sets in the
second row list of sets that meets this requirement.
The code that follows is the basis of what I've been working on. The
print statements show what's needed but I cannot think of a clever way
to code this requirement. I've experimented with dictionaries but I've
come to the conclusion that a boolean test is what's needed to weed out
the sets that don't meet the requirements.
Any code snippets or ideas will be greatly appreciated.
#row = [{7,3},{5},{4,8,6},{7,8},{1},{9,3},{7,9},{4,6,3},{2}]
row = [{5},{6},{3},{4,7,5},{1,2,4,5},{1,7,5},{1,2,4,7,9},{8},{1,2,4,7,9}]
set_list = [{1, 2}, {1, 3}, {1, 4}, {1, 5}, {1, 6}, {1, 7}, {1, 8}, {1, 9},
{2, 3}, {2, 4}, {2, 5}, {2, 6}, {2, 7}, {2, 8}, {2, 9},
{3, 4}, {3, 5}, {3, 6}, {3, 7}, {3, 8}, {3, 9},
{4, 5}, {4, 6}, {4, 7}, {4, 8}, {4,9},
{5, 6}, {5, 7}, {5, 8}, {5, 9},
{6, 7}, {6, 8}, {6, 9},
{7, 8}, {7, 9},
{8, 9}
]
count_dict = {}
for i in range(len(set_list)):
count = 0
row_list = []
for j in range(9):
if set_list[i].issubset(row[j]) and len(row[j]) > 2:
row_list.append(j)
count += 1
count_dict['row'] = row_list
count_dict['count'] = count
count_dict['set'] = set_list[i]
print(set_list[i], ' ', row_list)
print(count_dict)
--
Regards,
Phil
More information about the Tutor
mailing list