I have a very annoying string formatting issue. I tried different approaches but i seem to be lost. This is my expected output: ["aa","b","c","dd"].
Sample code:
mylist = ['b','c']
mylisttmp = ','.join('"{0}"'.format(x) for x in mylist)
finalstr='"aa"' +","+"{}".format(mylisttmp) +","+'"dd"'
print([finalstr])
OUTPUT:['"aa","b","c","dd"'] #How to get rid of the end quotes,which is causing issues?
I did a lot of string splitting, joining etc but I am going round and round the same issue. I intended to use the formatted output with a tkinter property, as follows:
myComboBox['values']= ["aa","b","c","dd"]
Please direct me. Thank you
You don't actually want a string at all. You want a list that contains four strings.
mylist = ['b','c']
finalset = ["aa"] + mylist + ["dd"]
print(finalset)
Output
>>> print(finalset)
['aa', 'b', 'c', 'dd']
>>>