Factorio is a game about building factories and about automation. Items can be crafted (just like Minecraft) yourself, or crafted automatically by assembling machines. To help me expand my factories I created a little script in Python 3 that shows me what other items that I can produce once I create factory of an item.Given a list of Factorio item recipes in CSV format extracted from the game by this script (the sample input file is also there) and a tolerance which is a natural number that describes how many other dependent items I have to add, I produce a list of related recipes.import csvrecipes = {}tolerance = 0def append_ignore_none(dictionary, key, value):    if key in dictionary:        dictionary[key].add(value)    else:        dictionary[key] = {value}with open('rec.csv') as csvfile:    reader = csv.reader(csvfile)    for row in reader:        append_ignore_none(recipes, row[0], row[1])dependents = {}for kleft, vleft in recipes.items():    for kright, vright in recipes.items():        if kleft != kright and vleft.issuperset(vright):            needed_items = vleft.symmetric_difference(vright)            if len(needed_items) <= tolerance:                if len(needed_items) != 0:                    print(Factory of {0} can also produce {1}, just add {2}.format(kleft, kright, ,.join(needed_items)))                else:                    print(Factory of {0} can also produce {1}.format(kleft, kright))Sample output (tolerance = 0):Factory of logistic-chest-storage can also produce logistic-chest-requesterFactory of logistic-chest-storage can also produce logistic-chest-active-providerFactory of logistic-chest-storage can also produce logistic-chest-passive-providerFactory of empty-barrel can also produce steel-chestFactory of piercing-shotgun-shell can also produce big-electric-poleFactory of piercing-shotgun-shell can also produce piercing-bullet-magazineFactory of piercing-shotgun-shell can also produce heavy-armorFactory of piercing-shotgun-shell can also produce medium-electric-poleFactory of logistic-chest-requester can also produce logistic-chest-storageFactory of logistic-chest-requester can also produce logistic-chest-active-providerFactory of logistic-chest-requester can also produce logistic-chest-passive-providerFactory of productivity-module can also produce effectivity-moduleFactory of productivity-module can also produce speed-moduleFactory of iron-gear-wheel can also produce pipeFactory of iron-gear-wheel can also produce iron-chestFactory of iron-gear-wheel can also produce iron-stickFactory of iron-gear-wheel can also produce basic-bullet-magazineFactory of iron-gear-wheel can also produce steel-plateFactory of iron-gear-wheel can also produce basic-armorFactory of big-electric-pole can also produce piercing-shotgun-shellFactory of big-electric-pole can also produce piercing-bullet-magazineFactory of big-electric-pole can also produce heavy-armorFactory of big-electric-pole can also produce medium-electric-poleFactory of chemical-plant can also produce pumpjackFactory of player-port can also produce basic-inserterFactory of player-port can also produce rocket-launcherFactory of player-port can also produce radarFactory of player-port can also produce basic-mining-drillFactory of player-port can also produce assembling-machine-1Factory of pipe can also produce iron-gear-wheelFactory of pipe can also produce iron-chestFactory of pipe can also produce iron-stickFactory of pipe can also produce basic-bullet-magazineFactory of pipe can also produce steel-plateFactory of pipe can also produce basic-armorFactory of basic-inserter can also produce player-portFactory of basic-inserter can also produce rocket-launcherFactory of basic-inserter can also produce radarFactory of basic-inserter can also produce basic-mining-drillFactory of basic-inserter can also produce assembling-machine-1Factory of pistol can also produce shotgun-shellFactory of energy-shield-equipment can also produce night-vision-equipmentFactory of basic-electric-discharge-defense-equipment can also produce basic-laser-defense-equipmentFactory of lubricant can also produce solid-fuel-from-heavy-oilFactory of logistic-chest-active-provider can also produce logistic-chest-storageFactory of logistic-chest-active-provider can also produce logistic-chest-requesterFactory of logistic-chest-active-provider can also produce logistic-chest-passive-providerFactory of blueprint can also produce deconstruction-plannerFactory of iron-chest can also produce iron-gear-wheelFactory of iron-chest can also produce pipeFactory of iron-chest can also produce iron-stickFactory of iron-chest can also produce basic-bullet-magazineFactory of iron-chest can also produce steel-plateFactory of iron-chest can also produce basic-armorFactory of poison-capsule can also produce slowdown-capsuleFactory of piercing-bullet-magazine can also produce piercing-shotgun-shellFactory of piercing-bullet-magazine can also produce big-electric-poleFactory of piercing-bullet-magazine can also produce heavy-armorFactory of piercing-bullet-magazine can also produce medium-electric-poleFactory of steel-chest can also produce empty-barrelFactory of stone-furnace can also produce stone-brickFactory of heavy-armor can also produce piercing-shotgun-shellFactory of heavy-armor can also produce big-electric-poleFactory of heavy-armor can also produce piercing-bullet-magazineFactory of heavy-armor can also produce medium-electric-poleFactory of rocket-launcher can also produce player-portFactory of rocket-launcher can also produce basic-inserterFactory of rocket-launcher can also produce radarFactory of rocket-launcher can also produce basic-mining-drillFactory of rocket-launcher can also produce assembling-machine-1Factory of pumpjack can also produce chemical-plantFactory of medium-electric-pole can also produce piercing-shotgun-shellFactory of medium-electric-pole can also produce big-electric-poleFactory of medium-electric-pole can also produce piercing-bullet-magazineFactory of medium-electric-pole can also produce heavy-armorFactory of curved-rail can also produce straight-railFactory of iron-stick can also produce iron-gear-wheelFactory of iron-stick can also produce pipeFactory of iron-stick can also produce iron-chestFactory of iron-stick can also produce basic-bullet-magazineFactory of iron-stick can also produce steel-plateFactory of iron-stick can also produce basic-armorFactory of night-vision-equipment can also produce energy-shield-equipmentFactory of radar can also produce player-portFactory of radar can also produce basic-inserterFactory of radar can also produce rocket-launcherFactory of radar can also produce basic-mining-drillFactory of radar can also produce assembling-machine-1Factory of gun-turret can also produce submachine-gunFactory of green-wire can also produce red-wireFactory of basic-bullet-magazine can also produce iron-gear-wheelFactory of basic-bullet-magazine can also produce pipeFactory of basic-bullet-magazine can also produce iron-chestFactory of basic-bullet-magazine can also produce iron-stickFactory of basic-bullet-magazine can also produce steel-plateFactory of basic-bullet-magazine can also produce basic-armorFactory of shotgun-shell can also produce pistolFactory of basic-mining-drill can also produce player-portFactory of basic-mining-drill can also produce basic-inserterFactory of basic-mining-drill can also produce rocket-launcherFactory of basic-mining-drill can also produce radarFactory of basic-mining-drill can also produce assembling-machine-1Factory of basic-transport-belt can also produce burner-inserterFactory of slowdown-capsule can also produce poison-capsuleFactory of deconstruction-planner can also produce blueprintFactory of burner-inserter can also produce basic-transport-beltFactory of effectivity-module can also produce productivity-moduleFactory of effectivity-module can also produce speed-moduleFactory of steel-plate can also produce iron-gear-wheelFactory of steel-plate can also produce pipeFactory of steel-plate can also produce iron-chestFactory of steel-plate can also produce iron-stickFactory of steel-plate can also produce basic-bullet-magazineFactory of steel-plate can also produce basic-armorFactory of speed-module can also produce productivity-moduleFactory of speed-module can also produce effectivity-moduleFactory of stone-brick can also produce stone-furnaceFactory of basic-laser-defense-equipment can also produce basic-electric-discharge-defense-equipmentFactory of assembling-machine-1 can also produce player-portFactory of assembling-machine-1 can also produce basic-inserterFactory of assembling-machine-1 can also produce rocket-launcherFactory of assembling-machine-1 can also produce radarFactory of assembling-machine-1 can also produce basic-mining-drillFactory of submachine-gun can also produce gun-turretFactory of red-wire can also produce green-wireFactory of logistic-chest-passive-provider can also produce logistic-chest-storageFactory of logistic-chest-passive-provider can also produce logistic-chest-requesterFactory of logistic-chest-passive-provider can also produce logistic-chest-active-providerFactory of basic-armor can also produce iron-gear-wheelFactory of basic-armor can also produce pipeFactory of basic-armor can also produce iron-chestFactory of basic-armor can also produce iron-stickFactory of basic-armor can also produce basic-bullet-magazineFactory of basic-armor can also produce steel-plateFactory of solid-fuel-from-heavy-oil can also produce lubricantFactory of straight-rail can also produce curved-railHow can I improve my script (Python best practices and maintainability)?
Finding items of related dependencies in Factorio
python