Text file has over 50K lines with this format
M:org.apache.mahout.common.RandomUtilsTest:testHashDouble():['(O)java.lang.Double:<init>(double)', '(M)java.lang.Double:hashCode()', '(S)org.apache.mahout.common.RandomUtils:hashDouble(double)', '(S)org.apache.mahout.common.RandomUtilsTest:assertEquals(long,long)', '(O)java.lang.Double:<init>(double)']
M:org.apache.mahout.common.RandomUtilsTest:testHashFloat():['(M)java.util.Random:nextLong()', '(M)java.util.Random:nextLong()', '(M)java.util.Random:nextLong()', '(S)org.apache.mahout.common.RandomUtilsTest:assertEquals(java.lang.String,long,long)']
M:org.apache.mahout.math.AbstractVectorTest:testAssignBinaryFunction():['(I)org.apache.mahout.math.Vector:assign(org.apache.mahout.math.Vector,org.apache.mahout.math.function.DoubleDoubleFunction)', '(O)java.lang.StringBuilder:<init>()', '(I)org.apache.mahout.math.Vector:getQuick(int)', '(S)org.apache.mahout.math.AbstractVectorTest:assertEquals(java.lang.String,double,double,double)']
M:org.apache.mahout.math.AbstractVectorTest:testAssignBinaryFunction2():['(S)org.apache.mahout.math.function.Functions:plus(double)', '(I)org.apache.mahout.math.Vector:assign(org.apache.mahout.math.function.DoubleFunction)', '(S)org.apache.mahout.math.AbstractVectorTest:assertEquals(java.lang.String,double,double,double)']
How do I read and format this data into a dictionary so that all of the methods in the [] are individual values and the string before the [ (test method) is the key? And how would I remove the '' before storing them as values in the dictionary? #python
Here is the code used to populate the text file. Now I am trying to take that txt file data and read/parse it back into another dictionary.
d = {}
with open("filtered.txt") as input:
for line in input:
(key, val) = line.strip().split(" ")
if str(key) in d:
d[str(key)].append(val)
else:
d[str(key)] = [val]
keys = []
for key in d:
keys.append(key)
keys.sort()
input.close()
with open('mahout-coverage.txt', 'w') as outfile:
for key in keys:
outfile.writelines('{}:{}'.format(key, d[key]) + "\n")