I have a file in the following format:
-2000 -2000 -2000
-2000 379 -2000
2000 379 -2000
2000 -2000 -2000
-2000 -2000 -2000
j
2000 379 -1190
2000 -2000 -1190
-2000 -2000 -1190
I need to read this file in python and save it in a list in the following format:
[[[-2000, -2000, -2000], [-2000 379 -2000], [2000, 379, -2000], [2000, -2000, -2000], [-2000, -2000, -2000]],[[2000, 379, -1190], [2000, -2000, -1190], [-2000, -2000, -1190]]]
while I read the file and saved the values in a list
file = open('filename', 'r')
vlist = file.readlines()
file.close
then I go to each of the "j" values in [-1, -1, -1] and use this value as a gap between the lists.
points = []
points = [list(map(int,elem.split())) if elem.strip().lower() != "j" else [-1, -1, -1] for elem in vlist]
and then using itertools, I can break this list down into groups that are divided into [-1, -1, -1] each time:
pointLists = [list(group) for val, group in groupby(points, lambda x: x == [-1,-1,-1]) if not val]
this, I believe, will give me my desired result, however, it does not work for the example file that I showed up, because it does not delete the # and the values that follow it.
I'm not sure how to remove # and the values that follow from the list, so any help would be great help. Thanks.
enter code here