Hi, returning the favor here with a suggestion of my own :)
You can greatly simplify your process in data-final-fixes like below.
-- Mostly copied from https://mods.factorio.com/mod/Lazy_Rabbit of author 'DarkyPupu'
-- Copied by DE_Schmitt
-- source = destination
local category_replacements = {
_default = "basic-crafting", -- _default stands in for nil key
handcraft = "basic-crafting",
handcrafting = "basic-crafting",
crafting = "advanced-crafting",
electronics = "electronics-machine"
}
-- Replace entries for basic-crafting with advanced-crafting if py is present
if mods["pypostprocessing"] then
for source, destination in pairs(category_replacements) do
if destination == "basic-crafting" then
category_replacements[source] = "advanced-crafting"
end
end
end
-- For every recipe, we replace the category if it has a relevant entry in category_replacements
for _, recipe in pairs(data.raw["recipe"]) do
local target_category = category_replacements[recipe.category or "_default"]
if target_category then -- We have an entry replacing the given category
recipe.category = target_category
end
end