split - How to take comma as text in comma separated text in python -


hi i'm new python , wanted know how enter comma text in comma separated string in python

for eg

text=raw_input("enter symbols").split(",")

input:

a, b, c, d, e,",",f

output:

["a","b","c","d",",","f"]

the problem here split statement, literally matches delimiter (, in case).

doing takes proper parsing, e.g. using csv module

import csv  text = raw_input("enter symbols:") reader = csv.reader([text], delimiter=',') symbols = next(reader) print(symbols) 

update: when scanning symbols, doubles , "" not valid.

for instance, a,a,b,,"," give ['a', 'a', 'b', '', ',']

so extension cleans symbols well:

import csv  text = raw_input("enter symbols:") reader = csv.reader([text], delimiter=',') symbols = set(data data in next(reader) if data) print(symbols) 

note: output set , might empty.


Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -