Python 检索所有x坐标的优雅方式

Python 检索所有x坐标的优雅方式,python,list,Python,List,假设我在笛卡尔坐标系中声明了一组点: points = [[1, 2], [3, 4], [5, 6], [7, 8]] 是否存在一种优雅的方法,可以将所有x坐标作为列表显示在点中 以下是我检索所有x坐标并将其作为列表返回的步骤: def getXs(points): length = len(points) xs = [None] * length for i in range(length): xs[i] = points[i][0] ret

假设我在笛卡尔坐标系中声明了一组点:

points = [[1, 2], [3, 4], [5, 6], [7, 8]]
是否存在一种优雅的方法,可以将所有x坐标作为列表显示在
点中

以下是我检索所有x坐标并将其作为列表返回的步骤:

def getXs(points):
    length = len(points)
    xs = [None] * length
    for i in range(length):
        xs[i] = points[i][0]
    return xs

我希望
getXs()
可以更简短、更优雅。

您可以像这样使用列表理解:

x_values=[i[0] for i in points]