<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_record(cls, attr_names, values):
 """ Convert values to a record to be inserted into a database. :param list attr_names: List of attributes for the converting record. :param values: Values to be converted. :type values: |dict|/|namedtuple|/|list|/|tuple| :raises ValueError: If the ``values`` is invalid. """


        try:
            # from a namedtuple to a dict
            values = values._asdict()
        except AttributeError:
            pass

        try:
            # from a dictionary to a list
            return [cls.__to_sqlite_element(values.get(attr_name)) for attr_name in attr_names]
        except AttributeError:
            pass

        if isinstance(values, (tuple, list)):
            return [cls.__to_sqlite_element(value) for value in values]

        raise ValueError("cannot convert from {} to list".format(type(values)))