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?
JavaScript
x
3
1
self.locx = [pobj.x for pobj in point_objects]
2
self.locy = [pobj.y for pobj in point_objects]
3
Advertisement
Answer
From the title, I understood that you want one line that computes both of these. You can use zip()
:
JavaScript
1
2
1
self.locx, self.locy = zip(*((pobj.x, pobj.y) for pobj in point_objects))
2