I am trying to teach myself Python to see whether I can use it in my research to handle some largish data files. I have been looking around and reading questions that have been asked here, but have not managed to make the file look up work. I have the following: In data.txt
I have one word per line. And dict.txt
is a JSON file where I have among others "word": "house", "meaning": "Haus"
.
I would like to look up each word of data.txt
in dict.txt
, and then add "meaning"
next to the word of data.txt
. So, if I have:
This
is
my
house
Processing it would result in:
This Dies
is ist
my mein
house Haus
Here, I found this piece of code, but nothing happens if I run it:
with open('data.txt') as f:
haystacks = list(f)
with open('dict.json') as f:
for line in f:
needle = line.strip()
for haystack in haystacks:
if needle in haystack:
print(haystack)
Is this even the right direction, or should I look at other modules? I am lost and would appreciate some pointers in the right direction.