From a list mylist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] how can I get a new list of lists composed of the first two elements of each “inside” list e.i. newlist = [[1, 2], [4, 5], [7, 8]]? Is there a one-liner that can do this efficiently (for large lists of lists)?
From a list mylist = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
Share
The easiest way is probably to use a list comprehension: