2 ms·
I don't know what I would do without list comprehensions. I can hardly imagine using iteration loops and counters anymore, and this is one among many reasons wh
by teilo 14y ago
I don't know what I would do without list comprehensions. I can hardly imagine using iteration loops and counters anymore, and this is one among many reasons why.
- recursive 14y agoList comprehensions don't really handle performing a list of actions for their side effects alone.
- teilo 14y agoThe example in the code was not a side-effect. They were creating a new list by invoking a function on every member of the old list. Here's the same thing re-written in Python: d = [compute_diffraction_at_wavelength(x, WAVELENGTH) for x in LensLayers] Or oldschool Python (and still faster, I think): d = map(compute_diffraction_at_wavelength(WAVELENGTH), LensLayers)