#the dictionary is
mydict = {'fruits': 'banana, apple,grapefruit',
'vegetables': 'tomato, potato,brocolli',
'dry fruits': 'cashew, almond' }
#expected output can be either list or string
banana, apple,grapefruit,tomato,potato,brocolli,cashew,almond
what I have until now is to put the values in a list and iterate through each element of the list and split each string
mydict = {'fruits': 'banana, apple,grapefruit',
'vegetables': 'tomato, potato,brocolli',
'dry fruits': 'cashew, almond' }
newlist = ''
mylist = list(mydict.values())
for ele in mylist:
x = ele.replace(' ', '').strip(',')
newlist = newlist + x +','
print(newlist)
Is there a better way to do it?