<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def _encode(cls, data, charsets):
 """Encode the data using the character sets in charsets. :param data: Data to be encoded. :param charsets: Sequence of charsets that are used to encode the barcode. Must be the exact amount of symbols needed to encode the data. :return: List of the symbol values representing the barcode. """

        result = []

        charset = charsets[0]
        start_symbol = cls._start_codes[charset]
        result.append(cls._sym2val[charset][start_symbol])

        cur = 0
        prev_charset = charsets[0]
        for symbol_num in range(len(charsets)):
            charset = charsets[symbol_num]

            if charset is not prev_charset:
                # Handle a special case of there being a single A in middle of two B's or the other way around, where
                # using a single shift character is more efficient than using two character set switches.
                next_charset = charsets[symbol_num + 1] if symbol_num + 1 < len(charsets) else None
                if charset == 'A' and prev_charset == next_charset == 'B':
                    result.append(cls._sym2val[prev_charset][cls.Special.SHIFT_A])
                elif charset == 'B' and prev_charset == next_charset == 'A':
                    result.append(cls._sym2val[prev_charset][cls.Special.SHIFT_B])
                else:
                    # This is the normal case.
                    charset_symbol = cls._char_codes[charset]
                    result.append(cls._sym2val[prev_charset][charset_symbol])
                    prev_charset = charset

            nxt = cur + (2 if charset == 'C' else 1)
            symbol = data[cur:nxt]
            cur = nxt
            result.append(cls._sym2val[charset][symbol])

        result.append(cls._calc_checksum(result))
        result.append(cls._sym2val[charset][cls.Special.STOP])

        return result