What do you mean "does not work"? Didn't run it myself, but it looks ok, other than deleting the city at the end of the inner loop (instead of the outer loop), when you presumably aren't quite done with it, and not having the categories available anymore when you process the second city.
Maybe you'd better explain why you want to delete them?