Swap a bunch of materials instances with unreal materials

I am trying to exchange a bunch of instance materials with unreal materials. I tried this with python but couldn’t get it to work.