Python code, copy dimension from one object to another
Swap A and B

For the most part, blender works the other way. The last selected object is the active object,aka  the context.object or context.active_object used by operators. An attribute of the context object can be assinged to all the other selected objects, in the list context.selected_objects 

Hence select B [C, D, E, F...] then A, A has context. The x dimension of A is set as the X dimension of B and other non active selected objects.  (and lazily A too not that it matters in this case as it is same)

import bpy
context = bpy.context
x = context.object.dimensions.x
for o in context.selected_objects:
    o.dimensions.x = x


Note: if an objects data has a zero dimension, for instance default plane in Z. there is no way of scaling to make its z dimension non zero.