I am new to python. I want to read data from file and store it in a multidimensional array. For example, I have this,
6 5.9
6.3 5.9
6.6 6.3
7.8 7.5
7.8 7.3
7.5 7.6
8.3 8
8.5 8
8.2 8.3
9.2 8.5
9 8.5
9.2 8.9
I want this stored in an array like this:
[ [['6', '5.9'], ['6.3', '5.9'], ['6.6', '6.3']],
[['7.8', '7.5'], ['7.8', '7.3'], ['7.5', '7.6']],
[['8.3', '8'], ['8.5', '8'], ['8.2', '8.3']],
[['9.2', '8.5'], ['9', '8.5'], ['9.2', '8.9']] ]
I have tried this so far:
with open("number.txt") as textFile:
lines = [line.split() for line in textFile]
print(lines)
And it gave me like this:
[['6', '5.9'], ['6.3', '5.9'], ['6.6', '6.3'], [], ['7.8', '7.5'], ['7.8', '7.3'], ['7.5', '7.6'], [], ['8.3', '8'], ['8.5', '8'], ['8.2', '8.3'], [], ['9.2', '8.5'], ['9', '8.5'], ['9.2', '8.9']]