I had a text file with some information like this:
A , 12
B , 34
A , 54
F , 60
I want to read the file, and store the information in a python dictionary, like this: {‘A’:[’12’,’54’,…], B:[’34’,….]…} and so on. But I am stuck with how to search every A in lines. This is my tried:
repo = {}
infile = open('test10.log','r')
lines = infile.readlines()[2:-1]
for i in lines:
module = ''.join(i.split(',')[:-1])
time = ''.join(i.split(',')[1:]).replace('\n','')
if not module in repo:
repo[module] = time
Thanks for your help!.
There is not such a data structure like
{A:{12,54,...}, B:{34,....}. However:will give you a dict of lists:
Is this what you want?