Is there a way to combine the following two list comprehensions?

Question:

I have a list of "point_objects", from which I build locx and locy. Please see below. Can these two list comprehensions be brought to just a single line?

self.locx = [pobj.x for pobj in point_objects]
self.locy = [pobj.y for pobj in point_objects]

Answers:

From the title, I understood that you want one line that computes both of these. You can use zip():

self.locx, self.locy = zip(*((pobj.x, pobj.y) for pobj in point_objects))
Answered By: pigrammer
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.