I want to insert a nested list to mysql database.
Normally, we insert a list data to mysql like this:
list_data = ['Kate', 'apple']
sql = 'INSERT INTO table VALUES ('name', 'likes')'
cursor.execute(sql, list_data)
But if
list_data = ['Kate', ['apple', 'orange', 'banana']]
or
list_data = ['Kate', {'food': 'apple', 'sports': 'running'}]
how can I do? (I mean to save the python list or dict as a string in mysql.)
list_data = ['Kate', {'food': 'apple', 'sports': 'running'}]could be transformed toinput = ["Kate", "apple", "running"], where the column names areName,Food, andSportslist_data = ['Kate', "{'food': 'apple', 'sports': 'running'}"](note the quotes around the dictionary)