How do you extract the first and last elements from each sublist in a nested list?
For example:
x=[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
print(x)
#[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
The desired result-
[[1, 3], [4, 6], [7, 9]]
This is the closest I've seen-
a = [x[i][i] for i in (0, -1)]
print(a)
#[1, 9]