In the dictionary below, id_count gets incremented as soon as the loop begins just before the dictionary is created. I need to increment it again inside the dictionary within locations id. Why is the += operator not allowed inside the dictionary? for i in range(0, len(all_locations)): id_count += 1 object_sequence_count += 1 object_data_output = { "id": id_count, "sequence": object_sequence_count, "coordinate":{ "x": all_locations["coordinate"]["x"], "y": all_locations["coordinate"]["y"], "objIdentifier": all_locations["materialIdentifier"], "location":[ { "id": id_count += 1 #where the error is occurring } ] } } Continue reading...