This will do you job: >>> a = 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' >>> b = [] >>> for x in a.split(','): ... if (x.find("\"") > -1): ... x = x.strip("\"") ... b.append(x)
If you want reduce the lines of code u can go for this option: b = [x.strip("\"") for x in a.split(',')] So Just Cheerz, -Shambhu -----Original Message----- From: bruce g [mailto:bruceg113...@gmail.com] Sent: 14/06/2012 8:00 AM To: python-list@python.org Subject: string to list What is the best way to parse a CSV string to a list? For example, how do I parse: 'AAA,"BBBB,CCCC,DDDD",EEE,FFF,GGG' to get: ['AAA','BBB,CCC,DDDD','EEE','FFF','GGG'] Thanks, Bruce -- http://mail.python.org/mailman/listinfo/python-list