Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to convert a tuple in a list to a normal list?

language: Python 3.7.0
mysql-connector-python==8.0.31

I’m working on a website and have just implemented a database. The response I’m getting from the database looks like this:

[('indigo', 'admin')]

How do I extract the two values from the tuple in a list and convert it to a list only?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Expected output:

["indigo", "admin"]

Thanks,

indigo

>Solution :

You can use:

response=[('indigo', 'admin')]

data=[response[0][i] for i in [0,1]]

data

Output

['indigo', 'admin']
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading