I have the following string
c='a,b,c,"d,e",f,g'
and I want to get
b=['a','b','c','d,e','f','g']
so
b[3]=='d,e'
any ideas? the problem with c.split(',')
is that it splits also 'd,e'
[I have see an answer here for C++, that of course didn't help me]
Many Thanks
You can use the Python string split() function to split a string (by a delimiter) into a list of strings. To split a string by comma in Python, pass the comma character "," as a delimiter to the split() function. It returns a list of strings resulting from splitting the original string on the occurrences of "," .
Given an input string that is comma-separated instead of space. The task is to store this input string in a list or variables. This can be achieved in Python using two ways: Using List comprehension and split()
Use str. split() to convert a comma-separated string to a list. Call str. split(sep) with "," as sep to convert a comma-separated string into a list.
Use input(), map() and split() function to take space-separated integer input in Python 3. You have to use list() to convert the map to a list.
You could use the CSV module if c
should indeed be the below...
import csv
c = 'a,b,c,"d,e",f,g'
print next(csv.reader([c]))
# ['a', 'b', 'c', 'd,e', 'f', 'g']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With