I am trying to get all the data from .txt file looks like this:
F 16 D 1 E 4 D 4 F 4 E 8
D 3 D 1 E 4 D 4 A 4 F 8
D 3 D 1
I want to sort all data in one list:
['F', '16', 'D', '1', 'E', '4', 'D', '4', 'F', '4', 'E', '8', 'D', '3', 'D',
'1', 'E', '4', 'D', '4', 'A', '4', 'F', '8', 'D', '3', 'D', '1']
This is code:
with open("sample2.txt") as file:
data = file.readlines()
data = [x.strip() for x in data]
print(data)
new_data = list(" ".join(data).replace(" ", ""))
return new_data
But I am getting output:
['F', '1', '6', 'D', '1', 'E', '4', 'D', '4',...]
1, 6 from one element 16 are separated. It works only if all elements in file consists from only one digit. What is the way so solve the problem?