|
|
|
|
|
by claytonjy
1992 days ago
|
|
As another point of comparison, as of python 3.8 you can do this in one list comp without nesting or double-computing areas with the walrus: result = [area for x,y in zip(heights,widths) if (area := to_area(x,y)) > 10]
I don't think that's very easy to read; I'd opt for two list comps like areas = [to_area(x,y) for x,y in zip(heights,widths)]
result = [area for area in areas if area > 10]
But I agree with OP that map+filter is easier to read. |
|
In scala:
---
val widths = Seq(1,2,3)
val heights = Seq(4,5,6)
widths.zip(heights).foreach { case (w, h) => {
}}println(area) // error: not found: value area