I have a txt file (dictionary.txt) that I would like to load into my script as a dictionary. How can I do so?
file dictionary.txt
{'YAL008W': 25, 'YBR255W': 50, 'YGR164W': 37, 'YGR131W': 40, 'YNL003C': 11,
'YBR135W': 2, 'YBR160W': 6, 'YJL082W': 79, 'YJL142C': 4, 'YPL191C': 38,
'YGL215W': 31, 'YKL074C': 33, 'YJL077C': 67, 'YKL096W-A': 22, 'YIL124W': 60,
'YLR364C-A': 2, 'YPL039W': 58, 'YNL170W': 16, 'YGL141W': 62, 'YJL179W': 15,
'YDR316W-A': 13, 'YDR316W-B': 139, 'YKL083W': 25, 'YOR009W': 25,
'YKL029C': 395, 'YPL166W': 31, 'YKL052C': 20, 'YOL034W': 29, 'YBL008W': 42,
'YIL062C': 2, 'YCL023C': 27}
Code:
f=open('dictionary.txt', 'r')
with f as dic1:
dictionary1=eval(dic1.read())
This inputs it as a dictionary, but I was wondering if there is a faster way to do so.