Below is the code I got. However, I don't know how to get rid of the last comma. I just want the key separated from the value with a space, and then a comma after it to separate it from the next key.
Also, a question on files. If I open a file and read it, and want to read the file again, is there no way to get the cursor to the beginning of the file without closing and opening the file again?
def dict_to_str(d):
""" (dict) -> str
Return a string containing each key and value in d. Keys and
values are separated by a blank space. Each key-value pair is
separated by a comma.
>>> dict_to_str({3: 4, 5: 6})
'3 4,5 6'
"""
s = ''
for (k, v) in d.items:
s = s + str(k) + " " + str(v) + ','
return s
dictto string and changing position in file without reopening?