I have the following code for a total of four text files all containing a few different keywords. They are called test1.txt, test2.txt, test3.txt and test4.txt. I want to transform it into a matrix/list of lists. I have the following code.
temp = [''] + list(sample_collection) values = list(sample_collection['test1.txt']) sample_collection = [temp] + [[x] + [v.get(x, 0) for v in sample_collection.values()] for x in values]
However, I want to modify it to include not only the keywords from test1, but all other unique keywords from the other files. I have no clue how to do so. Is there a way to do so with that piece of code?
[['', 'test1.txt', 'test2.txt', 'test3.txt', 'test4.txt'], ['apple', 1, 0, 2, 1], ['banana', 1, 1, 1, 1], ['lemon', 1, 1, 0, 0], ['grape', 0, 0, 0, 1]]