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

remove first and last quote from python list

I have a list

list = ['1,2,3,4,5,6,7']

I want my list as under:

desire output = [1,2,3,4,5,6,7]

how to get this, i read other similar answer where strip method used. i had tried strip but strip method not work with list, it work with strings.

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

'list' object has no attribute 'strip'

>Solution :

What you have is a list with a single str element. To get the list you want, try:

lst = ['1,2,3,4,5,6,7']
>>> list(map(int, lst[0].split(",")))
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