I have a few thousand lists in text files. For example:
text1.txt:
1,2,3,4
text2.txt:
a,b,c,d
I want to open all of my text files and put them all into one list, like so:
[1,2,3,4,a,b,c,d]
However, all of the loops I have tried either give me a list of arrays like:
[array([1,2,3,4]),array([a,b,c,d)]]
Or they just give me back [1,2,3,4].
This is the most recent code I tried:
file_list=glob.glob(file_dir+'/*.txt')
data=[]
for file_path in file_list:
data.append(np.concatenate([np.genfromtxt(file_path, delimiter=',')]))
Which just puts the first list into data. Without concatenate, it puts the two lists into data as a list of two separate arrays.