python - creating a 2D dictionary from a string -
so have program creates 2d dictionary (that say, dictionary maps values each dictionary). , store string representation of in file looks this.
emission dictionary: {' ': {'a': 0.07801487990167236, 'c': 0.01087880333163352, 'e': 0.048483897540501315, 'd': 0.07454333869428209, 'g': 0.08257822408765805, 'f': 0.028334575504386825, 'i': 0.0395206527281999, 'h': 0.04682984871664117, 'k': 0.0453653944219982, 'm': 0.028569934230311587, 'l': 0.07167326978647734, 'n': 0.04869964303926568, 'q': 0.03551301664509212, 'p': 0.09113612887197793, 's': 0.07330770538317709, 'r': 0.046064932857385686, 't': 0.06238313785483597, 'w': 0.009427424521764144, 'v': 0.05475359248944155, 'y': 0.023921599393297507}, 'b': {'a': 0.051661016949152545, 'c': 0.013559322033898305, 'e': 0.042305084745762715, 'd': 0.042440677966101695, 'g': 0.06454237288135593, 'f': 0.06142372881355932, 'i': 0.07294915254237289, 'h': 0.03064406779661017, 'k': 0.037694915254237286, 'm': 0.03023728813559322, 'l': 0.09749152542372881, 'n': 0.0408135593220339, 'q': 0.03023728813559322, 'p': 0.0471864406779661, 's': 0.04854237288135593, 'r': 0.0568135593220339, 't': 0.07525423728813559, 'w': 0.022779661016949154, 'v': 0.09383050847457627, 'y': 0.03959322033898305}, 'e': {'a': 0.06982017732828409, 'c': 0.016122814576294248, 'e': 0.04564729358942379, 'd': 0.03127810910300309, 'g': 0.053750274004701545, 'f': 0.050273248826504004, 'i': 0.09449949734309925, 'h': 0.023099541183851487, 'k': 0.03690181939121824, 'm': 0.023530389955932485, 'l': 0.10936000060470003, 'n': 0.026894033878319235, 'q': 0.03390099548742602, 'p': 0.02086970981957263, 's': 0.047219513670000074, 'r': 0.04811144621571162, 't': 0.07031905485385156, 'w': 0.019433547245969296, 'v': 0.13722155453260468, 'y': 0.04174697838953264}, 'g': {'a': 0.10475171232876712, 'c': 0.009289383561643836, 'e': 0.08446061643835616, 'd': 0.08240582191780822, 'g': 0.05898972602739726, 'f': 0.04794520547945205, 'i': 0.030950342465753424, 'h': 0.029794520547945205, 'k': 0.04897260273972603, 'm': 0.0194777397260274, 'l': 0.08625856164383562, 'n': 0.040625, 'q': 0.045077054794520545, 'p': 0.06643835616438357, 's': 0.06357020547945205, 'r': 0.05333904109589041, 't': 0.04041095890410959, 'w': 0.023715753424657534, 'v': 0.0293236301369863, 'y': 0.03420376712328767}, 'i': {'a': 0.0625, 'c': 0.0, 'e': 0.010416666666666666, 'd': 0.14583333333333334, 'g': 0.10416666666666667, 'f': 0.041666666666666664, 'i': 0.07291666666666667, 'h': 0.020833333333333332, 'k': 0.03125, 'm': 0.041666666666666664, 'l': 0.08333333333333333, 'n': 0.0625, 'q': 0.0, 'p': 0.03125, 's': 0.020833333333333332, 'r': 0.020833333333333332, 't': 0.09375, 'w': 0.010416666666666666, 'v': 0.13541666666666666, 'y': 0.010416666666666666}, 'h': {'a': 0.1327115346551383, 'c': 0.00959732742431484, 'e': 0.08545386958641699, 'd': 0.047079042777624903, 'g': 0.0352368676408823, 'f': 0.036472740790089844, 'i': 0.05859293910910925, 'h': 0.021516744632882917, 'k': 0.053374271631400835, 'm': 0.031389246938075994, 'l': 0.1245866342249965, 'n': 0.030240271119672108, 'q': 0.0567053359788743, 'p': 0.021468468337991996, 's': 0.039340352706610474, 'r': 0.06604679904026725, 't': 0.04166244249086371, 'w': 0.016244973230794484, 'v': 0.06256125054914285, 'y': 0.029718887134850176}, 's': {'a': 0.06946781854220427, 'c': 0.012173230113317626, 'e': 0.05912711769325704, 'd': 0.0848199259508583, 'g': 0.14377875014024458, 'f': 0.03349040727027937, 'i': 0.03603350910654849, 'h': 0.026964359175735815, 'k': 0.04772055798646172, 'm': 0.019129361606641984, 'l': 0.05858483862522906, 'n': 0.058435244399566176, 'q': 0.0371367665208123, 'p': 0.0511986237331239, 's': 0.06621414413403642, 'r': 0.05301245371928644, 't': 0.06103444407045888, 'w': 0.009667526833464229, 'v': 0.04414899584876024, 'y': 0.02786192452971315}, 't': {'a': 0.07681286088862779, 'c': 0.006318685254968264, 'e': 0.06944822546673735, 'd': 0.08379063802960182, 'g': 0.18785551559611996, 'f': 0.026034129497227516, 'i': 0.020833034831573366, 'h': 0.028527216196466695, 'k': 0.050119639505394525, 'm': 0.013984210450904819, 'l': 0.05532073417104867, 'n': 0.07512214692017824, 'q': 0.04357170489877208, 'p': 0.07099565859040305, 's': 0.05172438496697376, 'r': 0.04718238218732538, 't': 0.038155688965942146, 'w': 0.009313254910950955, 'v': 0.023913572994426376, 'y': 0.02097631567635723}} transition dictionary: {' ': {' ': 0.5832317477143236, 'b': 0.028011130250430633, 'e': 0.09403736584073141, 'g': 0.024983437127335365, 'i': 7.28766397243938e-05, 'h': 0.07186961706638399, 's': 0.11708625944083742, 't': 0.0807075659202332}, 'b': {' ': 0.6012203389830508, 'b': 0.03105084745762712, 'e': 0.032406779661016946, 'g': 0.019932203389830507, 'i': 0.00013559322033898305, 'h': 0.04542372881355932, 's': 0.12298305084745763, 't': 0.14684745762711865}, 'e': {' ': 0.11143781463060666, 'b': 0.0022222558164144584, 'e': 0.8144114045563803, 'g': 0.003990990037642293, 'i': 0.0, 'h': 0.005041648399824638, 's': 0.03269134831970249, 't': 0.030204538239429167}, 'g': {' ': 0.09708904109589041, 'b': 0.00821917808219178, 'e': 0.017636986301369863, 'g': 0.7022688356164384, 'i': 0.0, 'h': 0.04297945205479452, 's': 0.06528253424657535, 't': 0.06652397260273972}, 'i': {' ': 0.020833333333333332, 'b': 0.010416666666666666, 'e': 0.0, 'g': 0.0, 'i': 0.8020833333333334, 'h': 0.041666666666666664, 's': 0.07291666666666667, 't': 0.052083333333333336}, 'h': {' ': 0.01848499331373316, 'b': 0.0003813827296382657, 'e': 0.0006372470925601402, 'g': 0.0029014053229442748, 'i': 9.655258978183943e-06, 'h': 0.9098102258847838, 's': 0.010379403401547738, 't': 0.057395686995814446}, 's': {' ': 0.39081491454429856, 'b': 0.02558061258835409, 'e': 0.10101350087886607, 'g': 0.019746437787501403, 'i': 0.0, 'h': 0.05508807360035903, 's': 0.34791877033546503, 't': 0.059837690265155764}, 't': {' ': 0.23972661623108665, 'b': 0.014099037138927097, 'e': 0.059791953232462176, 'g': 0.012207702888583218, 'i': 7.164144887666208e-05, 'h': 0.0412368179734067, 's': 0.11870988078862907, 't': 0.5141563502980284}} what i've been trying figure out how @ later point have code reads in file , can translate corresponding 2d dictionaries. know of way this?
python dictionaries nothing json data structure. use json.dumps function convert dictionary string , store file. later use json.loads function convert string dictionary.
more information functions can found here
Comments
Post a Comment