As of reading the following input.txt file:1 6 141 2 71 3 92 3 102 4 153 6 23 4 114 5 65 6 9I wanted to make a list of lists containing each line as a list of integers[[1, 6, 14], [1, 2, 7], [1, 3, 9], ... [5, 6, 9]] I achieved that by doing the followingwith open('input.txt', 'r') as f:    # gets lines as list of strings [['1, 2, 3,', ...]]         nodes_list = [n.split() for n in f.readlines()]     # convert strings inside the lists to int's [[1, 2, 3], ...]    nodes_list = [[int(y[0]), int(y[1]), int(y[2])] for y in nodes_list]Is there any way that I can achieve the same with a single comprehension list, without the need of having two separated ones? If not, maybe some cleaner way of doing it?
List comprehension for reading lists of integers
python;python 3.x
What about:with open('input.txt', 'r') as f:      nodes_list = [[int(item) for item in line.split()] for line in f]Notice how:rather than iterating over f.readlines(), which creates a list of the lines in the file, we iterate over f, which produces the same result, but as a generator,rather than first creating a potentially huge list of lists of strings, then converting it to a list of lists of ints, only a single row is instantiated at a time.