<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def merge_tags(left, right, factory=Tags):
 """ Merge two sets of tags into a new troposphere object Args: left (Union[dict, troposphere.Tags]):
 dictionary or Tags object to be merged with lower priority right (Union[dict, troposphere.Tags]):
 dictionary or Tags object to be merged with higher priority factory (type):
 Type of object to create. Defaults to the troposphere Tags class. """


    if isinstance(left, Mapping):
        tags = dict(left)
    elif hasattr(left, 'tags'):
        tags = _tags_to_dict(left.tags)
    else:
        tags = _tags_to_dict(left)

    if isinstance(right, Mapping):
        tags.update(right)
    elif hasattr(left, 'tags'):
        tags.update(_tags_to_dict(right.tags))
    else:
        tags.update(_tags_to_dict(right))

    return factory(**tags)