s = "ez , dad , tada"
print(s.split(" , "))
prints the following:
['ez', 'dad', 'tada']
The problems is, I need the output to be with double quotes, not with single quotes, like this:
["ez", "dad", "tada"]
s = "ez , dad , tada"
print(s.split(" , "))
prints the following:
['ez', 'dad', 'tada']
The problems is, I need the output to be with double quotes, not with single quotes, like this:
["ez", "dad", "tada"]
Credit to @fn. for this posting
Example:
import json
s = "ez , dad , tada"
print(json.dumps(s.split(" , ")))
Output:
["ez", "dad", "tada"]
You've shown that you used the following code to split up a string into an list:
s = "ez , dad , tada"
split_data = s.split(" , ")
Now that you have the data in an list, you can reformat it by using the .join()
method of a string, to turn the list into a string. According to your example, you want to format the string like ["ez", "dad", "tada"]
, so what you can do is to merge each 2 items with ", "
since that seems to be the seperating string.
separator = '", "'
print('["' + separator.join(split_data) + '"]')