I want to add 3 different values of 3 different dictionaries to 1 "all_in_one" dictionary based on the same key.
I have 3 big dictionaries based on the same text corpora (each of the files in it contains the values from the same line -- multiple lines, actually -- of these files, but different columns of them). All 3 dictionaries have the same key.
They look like this:
tokens = {"token1": 10, "token2": 56, "token3": 90, ...}
lemmas = {"token1": "lemma1", "token2": "lemma2", "token2": "lemma3", ...}
categs = {"token1": "categX", "token2": "categY", "token3": "categZ", ...}
I want to add these values to another dictionary to have it look like this:
all_in_one = {"token1": [tokens[value1], lemmas[value1], categs[value1]],
"token2": [tokens[value2], lemmas[value2], categs[value2]], ... }
I have such a loop:
all_in_one = {}
for tk, tv in tokens.items():
for lk, lv in lemmas.items():
for ck, cv in categs.items():
if tk == lk == ck:
all_in_one[tk] = [tv, lv, cv]
The problem is, it works (don't know if it's fine), but with small amount of files. I have 500k files. Haven't tried to run it with the final corpora, because even the first try with 100 files took a few hours and haven't finished (100 files = 6500 tokens, so I assume it's 6500^3 loops...). I've only tested it with 10 and 20 files.
Is it even a proper loop for doing this (adding values of 3 dics into another dic)? If yes (I doubt, based on the time needed), maybe there's a way to optimize it?