Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def dict2file(d, filename):
- D1, D2 = dict(), dict()
- for i in d:
- if isinstance(i, int):
- D1[i] = d[i]
- else:
- D2[i] = d[i]
- with open(f"{filename}.txt", "w") as file:
- L1, L2 = sorted(D1.items()), sorted(D2.items())
- if any(L1):
- for i in L1:
- file.write(f"{i[0]} -> {i[1]}\n")
- elif any(L2):
- for i in L2:
- file.write(f"{i[0]} -> {i[1]}\n")
- print("File Written Successfully")
- d = {"12": 2,"11": 1,"A":31,'a': 30,'c': 1,'b': 17,'e': 9,'d': 52,'f': 11,
- 'g': 1,'h': 23,'13': 16,'k': 2,'l': 8}
- dict2file(d, "filename")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement