I can't find the solution to this issue I'm having, when I execute this code, I get the message "Invalid Syntax" on the 'else' command detailed below.
Any help extremely appreciated! :)
Expected results would be an original representation and an inverted one of the text file referenced.
f = open("dict_file.txt", "r")
s=f.read()
dc=eval(s)
f.close()
print("Original Dictionary : ",dc)
def invert_dict(d):
inverse = dict()
for key in d:
values = d[key]
for value in values:
if value not in inverse:
inverse[value] = [key]
else:
inverse[value].append(key)
return inverse
inv_d=invert_dict(dc)
print("Inverted Dictionary : ",inv_d)
f=open("f2.txt","w+")
f.write(str(inv_d))
f.close()
Aucun commentaire:
Enregistrer un commentaire