T
T
Timebird2016-11-20 02:27:07
Python
Timebird, 2016-11-20 02:27:07

How to create a loop, on each iteration of which a list with a new name is created?

There are n files with numbers (each file has the same number of numbers). It is necessary to create a loop that takes on every 1, 2, ..., n-th iteration 1, 2, ..., n-th file and pushes its contents into the corresponding list_1, list_2, ..., list_n. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
L
lcd1232, 2016-11-20
@lcd1232

file_names = ['a.txt', 'b.txt', 'c.txt']
files = []
for file_name in file_names:
        with open(file_name, 'r') as file:
                files.append(file.readlines())

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question