python - Elegant way to retrieve all x-coordinates -


let's have set of points declared in cartesian coordinate system:

points = [[1, 2], [3, 4], [5, 6], [7, 8]] 

does there exist elegant way get x-coordinates list in points?

the following i've done retrieve x-coordinates , return them list:

def getxs(points):     length = len(points)     xs = [none] * length     in range(length):         xs[i] = points[i][0]     return xs 

i wish getxs() shorter , more elegant.

you can use list comprehension this:

x_values=[i[0] in points] 

Comments

Popular posts from this blog

routing - AngularJS State management ->load multiple states in one page -

python - GRASS parser() error -

Swift game error message -