I have a list with 20 dictionaries that are similar to these:
dic1 = {"aa":1, "ba":1, "ca":1, "dd":2, "ee":2, "fa":2, "ga":4, "hh":4, "ia":1}
dic2 = {"aa":1, "bc":1, "cd":2, "dd":2, "ea":2, "fg":2, "gk":4, "hh":4, "mb":5}
dic3 = {"ab":1, "bd":2, "cm":2, "dj":2, "ej":2, "fa":2, "gg":2, "ha":4}
I have to apply the same formula to each dictionary and I would like to output a list with the results of the formula per dictionary (thus, a list with 20 integers).
The formula will vary according to the "value" amount:
In summary, per dictionary I need to calculate final_formula:
If value == 1, then my partial formula is: formula1 = (number of unique keys that contain value 1) [1 - x + x ((x-10/x) ^1]
If the value is anything above 1 (else), then my intermediary formulas are formulan = (number of unique keys with value i) [(value i) - x + x ((x-10/x)^(value i)]
final_formula = formula 1 + formula2 + formula3 (n formulas, where n is the number of distinct values =! 1). X is a constant that I will define. The output should be an integer.
A practical example: For my dic1, I have 4 keys with value ==1, 3 keys with value ==2, 2 keys with value ==4 The formula for dic1 thus is:
final_formula_dic1 = 4 [1 - x + x ((x-10/x)^1] + 3 [2 - x + x ((x-10/x)^2] + 2 * [4 - x + x ((x-10/x)^4]
For my dic2, I have 2 keys with value ==1, 4 keys with value == 2, 2 keys with value == 4, 1 key with value == 5 The formula for dic2 thus is:
final_formula_dic2 = 2 [1 - x + x ((x-10/x)^1] + 4 [2 - x + x ((x-10/x)^2] + 2 * [4 - x + x ((x-10/x)^4]
For my dic3, I have 1 key1 with value ==1, 6 keys with value == 2, 1 key with value == 4 The formula for dic3 thus is:
final_formula_dic3 = 1 [1 - x + x ((x-10/x)^1] + 6 [2 - x + x ((x-10/x)^2] + 1 * [4 - x + x ((x-10/x)^4]
I am applying each formula manually to each dictionary, but I have too many dictionaries in my list and this is error prone.
I would really like to iterate over all dictionaries and apply the formula (since it is the same criteria to all dictionaries) and create a list with results, for example, list = ['final_formula_dic1', 'final_formula_dic2', 'final_formula_dic3'...] which would be integers, for instance: list = ['3000', '3200', '1300'...].
I hope this makes sense. Thank you very much in advance!
This has no connection to bioinformatics, and appears to be an ordinary programming problem. Given your level of explanation and understanding, I think you should be able to figure it out with some research.