<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write(address, buf):
 """ Prepares an i2c write transaction. :param address: Slave address. :type address: int :param buf: Bytes to write. Either list of values or str. :type buf: list :return: New :py:class:`i2c_msg` instance for write operation. :rtype: :py:class:`i2c_msg` """

        if sys.version_info.major >= 3:
            if type(buf) is str:
                buf = bytes(map(ord, buf))
            else:
                buf = bytes(buf)
        else:
            if type(buf) is not str:
                buf = ''.join([chr(x) for x in buf])
        arr = create_string_buffer(buf, len(buf))
        return i2c_msg(
            addr=address, flags=0, len=len(arr),
            buf=arr)