Add lines from files to corresponding dictionaries I have to iterate through multiple text files. For each file I read its contents and append each line to its corresponding dictionary to then build a JSON file.
Each text file has the following structure:

Line 1: The title key.
Line 2: The name key.
Line 3: The date key.
Line 4: The feedback key.

Here is an example of two of these files:
001.txt

Great Customer Service
John
2017-12-21
The customer service here is very good. They helped me find a 2017 Camry with good condition in reasonable price. Compared to other dealers they provided the lowest price. Definitely recommend!

002.txt

You will find what you want here
Tom
2019-06-05
I've being look around for a second handed Lexus RX for my family and this store happened to have a few of those. The experience was similar to most car dealers. The one I ended up buying has good condition and low mileage. I am pretty satisfied with the price they offered.

My approach is successful but I wonder if there is a better and faster approach of joining each line to its corresponding dictionary.
Additionally do I need to write with open('file', 'r') for each file? Even when I use os.listdir() I still have the same issue.
import json

l1 = []
l2 = []

with open(&quot;C:/Users/user/Desktop/001.txt&quot;) as file1, open(&quot;C:/Users/user/Desktop/002.txt&quot;) as file2:
    for line1, line2 in zip(file1, file2):
      if not line1.isspace() and not line2.isspace():
        l1.append(line1.rstrip())
        l2.append(line2.rstrip())

Dict = {}

Dict['dictio1'] = {'title': &quot;&quot;, &quot;name&quot;: &quot;&quot;, &quot;date&quot;: &quot;&quot;, &quot;feedback&quot;: &quot;&quot;}

Dict['dictio2'] = {'title': &quot;&quot;, &quot;name&quot;: &quot;&quot;, &quot;date&quot;: &quot;&quot;, &quot;feedback&quot;: &quot;&quot;}

Dict['dictio1'][&quot;title&quot;] = l1[0]
Dict['dictio1'][&quot;name&quot;] = l1[1]
Dict['dictio1'][&quot;date&quot;] = l1[2]
Dict['dictio1'][&quot;feedback&quot;] = l1[3]

Dict['dictio2'][&quot;title&quot;] = l2[0]
Dict['dictio2'][&quot;name&quot;] = l2[1]
Dict['dictio2'][&quot;date&quot;] = l2[2]
Dict['dictio2'][&quot;feedback&quot;] = l2[3]   


with open('file.json', 'w') as file_json:
    json.dump(Dict, file_json, indent=2)


{
  &quot;dictio1&quot;: {
    &quot;title&quot;: &quot;Great Customer Service&quot;,
    &quot;name&quot;: &quot;John&quot;,
    &quot;date&quot;: &quot;2017-12-21&quot;,
    &quot;feedback&quot;: &quot;The customer service here is very good. They helped me find a 2017 Camry with good condition in reasonable price. Campared to other dealers they provided the lowest price. Definttely recommend!&quot;
  },
  &quot;dictio2&quot;: {
    &quot;title&quot;: &quot;You will find what you want here&quot;,
    &quot;name&quot;: &quot;Tom&quot;,
    &quot;date&quot;: &quot;2019-06-05&quot;,
    &quot;feedback&quot;: &quot;I've being look around for a second handed Lexus RX for my family and this store happened to have a few of those. The experience was similar to most car dealers. The one I ended up buying has good condition and low mileage. I am pretty satisfied with the price they offered.&quot;
  }
}
There are some ways you can improve your code:

Rather than building a dictionary and then manually assigning each value you can assign to l1[0] etc straight away.
Dict['dictio1'] = {'title': &quot;&quot;, &quot;name&quot;: &quot;&quot;, &quot;date&quot;: &quot;&quot;, &quot;feedback&quot;: &quot;&quot;}
Dict['dictio1'][&quot;title&quot;] = l1[0]
Dict['dictio1'][&quot;name&quot;] = l1[1]
Dict['dictio1'][&quot;date&quot;] = l1[2]
Dict['dictio1'][&quot;feedback&quot;] = l1[3]

Dict[&quot;dictio1&quot;] = {
    &quot;title&quot;: l1[0],
    &quot;name&quot;: l1[1],
    &quot;date&quot;: l1[2],
    &quot;feedback&quot;: l1[3],
}


You should use a for loop over the paths and have the with inside it. Only building one dictionary at a time.
for key, path in ...:
    with open(path) as f:
        lines = []
        for line in f:
            if not line.isspace():
                lines.append(line.rstrip())
        Dict[key] = {
            &quot;title&quot;: l1[0],
            &quot;name&quot;: l1[1],
            &quot;date&quot;: l1[2],
            &quot;feedback&quot;: l1[3],
        }


We can use a list comprehension to build lines with some sugar.
lines = [line.rstrip() for line in f if not line.isspace()]



Putting this all together we can get:
data = {}
paths = [
    (&quot;dictio1&quot;, &quot;C:/Users/user/Desktop/001.txt&quot;),
    (&quot;dictio2&quot;, &quot;C:/Users/user/Desktop/002.txt&quot;),
]
for key, path in paths:
    with open(path) as f:
        lines = [line.rstrip() for line in f if not line.isspace()]
        data[key] = {
            &quot;title&quot;: lines[0],
            &quot;name&quot;: lines[1],
            &quot;date&quot;: lines[2],
            &quot;feedback&quot;: lines[3],
        }

with open('file.json', 'w') as file_json:
    json.dump(data, file_json, indent=2)

I would recomend you change your JSON structure to remove the outer dictionary and instead use a list. This would make all your code simpler not only building it here but consuming it later.
This would look like:
data = []
paths = [
    &quot;C:/Users/user/Desktop/001.txt&quot;,
    &quot;C:/Users/user/Desktop/002.txt&quot;,
]
for path in paths:
    with open(path) as f:
        lines = [line.rstrip() for line in f if not line.isspace()]
        data.append({
            &quot;title&quot;: lines[0],
            &quot;name&quot;: lines[1],
            &quot;date&quot;: lines[2],
            &quot;feedback&quot;: lines[3],
        })

with open('file.json', 'w') as file_json:
    json.dump(data, file_json, indent=2)