pythondouble-quotesquotingsingle-quotesoutput-formatting

python split problems I need the data output to look different


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"]

Solution

  • Credit to @fn. for this posting

    Example:

    import json
    
    s = "ez , dad , tada"
    
    print(json.dumps(s.split(" , ")))
    

    Output:

    ["ez", "dad", "tada"]