Beginner, trying to select and duplicate objects

This is just an exercise but can anyone help me understand why the objects in the screenshot are being copied the way they are?

My script finds three objects by name, selects them and duplicates them but I get extra copies that are reducing by 1 each time.

Thanks

Your duplicates and transforms are based on object selections, first time 1 is selected and duplicated, second time 2 are selected and duplicated and so on.
And your duplicates are added to bpy.data.objects so your loop maybe loop for ever.

Thanks @JuhaW

I think I got this last night - the script selects the first object, duplicates it, finds the second, duplicates it but with the first still active. So for three objects there’ll be three copies for the first, two for the second etc.

Even though bpy.ops.object.duplicate() duplicates an object and deselects the original, it creates a new and selected copy.

EDIT:
solved this for myself - I took the duplicate() out of the for loop iteration so that I only got one copy of all the selected objects