That code as written will just use one dict_sub and keep replacing the
values in it, storing a reference to dict_sub for every dict[key]. So
I'm not surprised you're getting duplicated items. They should all be
duplicated. You can put dict_sub = {} inside the loop and it'll behave
like you expect.
Hi
A couple of things
1. You should try not to use dict as a name . dict is a builtin and
is the other way to create a new dictionary ie. dict()
plus you often use dict for type comparisons isinstance
(sub_dict,dict) etc
2. I am having trouble following your example, but I wonder if
sub