Write dict_to_string(D) that converts a dictionary back into the line based
string format used by dict_from_string: one key,value pair per line, joined by
newlines, with the pairs kept in the dictionary's own order. There is no trailing
newline. Use a comprehension rather than an explicit loop.
An empty dictionary produces the empty string ''.
Example
dict_to_string({'Apple': 2, 'Banana': 3}) returns 'Apple,2\nBanana,3'.
Implement this function:
def dict_to_string(D: dict) -> str:
Write the function only — the arguments are read for you and the return value is printed automatically.
Arguments arrive as one Python literal per line, in this order: D.
Input
{'Apple': 2, 'Banana': 3}
Output
'Apple,2\nBanana,3'