<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def set_tag(self, key, value, update_session=True):
 """Create or set the value of the tag with `key` to `value`. Returns `True` if the tag was created or updated or `False` if there were no changes to be made. Args: key (str):
 Key of the tag value (str):
 Value of the tag update_session (bool):
 Automatically add the change to the SQLAlchemy session. Default: True Returns: `bool` """

        existing_tags = {x.key: x for x in self.tags}
        if key in existing_tags:
            tag = existing_tags[key]

            if tag.value == value:
                return False

            tag.value = value
        else:
            tag = Tag()
            tag.resource_id = self.id
            tag.key = key
            tag.value = value
            self.tags.append(tag)

        if update_session:
            db.session.add(tag)
        return True