import json, sys, os, glob from collections import namedtuple Episode = namedtuple('Episode', ['n', 'date', 'title']) melevisione = dict() scarti = {'Il Genio della pietra'} for i in range(1, 18): with open(f'{i}.txt', 'r') as fp: c = json.loads(fp.read()) eps = [Episode(i[0], i[1], i[2]) for i in c] eps = [e for e in eps if e[2] not in scarti] melevisione[i] = eps expected = { 1: 103, 2: 162, 3: 151, 4: 127, 5: 144, 6: 165, 7: 144, 8: 156, 9: 130, 10: 135, 11: 100, 12: 128, 13: 45, 14: 100, 15: 100, 16: 75, 17: 70 } for k, v in melevisione.items(): if expected[k] == len(v): print(f'Stagione {k} OK'); continue missing = f'{k}, {expected[k]}, {len(v)}' segnate = set(map(lambda x: int(x[0]), v)) wanted = set(range(1, expected[k])) print(wanted - segnate) break