[Tutor] A dictionary question
Phil
phillor9 at gmail.com
Fri Nov 19 19:37:44 EST 2021
Thank you Mats. I just arrived at our camping site and I'm amazed that
there is some mobile phone service here. Once I've settled in I'll run
through your code to understand how it works.
> pairs = Counter()
>
> for s in set_list:
> for r in row:
> if s.issubset(r):
> pairs[tuple(sorted(s))] += 1
>
> for item, count in pairs.items():
> if count == 2: # candidate
> i, j = item
> # since we know we're only counting two things,
> # no need to use a Counter or dict here
> icount, jcount = 0, 0
> for r in row:
> if i in r:
> icount += 1
> if j in r:
> jcount += 1
> if icount == 2 and jcount == 2:
> print(f"{set(item)} found")
--
Regards,
Phil
More information about the Tutor
mailing list