27 May
2019
27 May
'19
7:44 a.m.
Am 27.05.19 um 06:12 schrieb Cameron Simpson:
On 26May2019 21:52, Montana Burr <montana.burr@gmail.com> wrote:
NumPy arrays have this awesome feature, where array == 3 does an element-wise comparison and returns a list. For example:
np.array([1,2,3,4,5])==3
returns
[False,False,True,False,False] It would be cool if Python had similar functionality for lists.
map(lamdba item: item==3, [1,2,3,4,5])
A list comprehension seems more pythonic to me: [item == 3 for item in [1, 2, 3, 4, 5]] or, if you want it to make it lazy, use generator expression: (item == 3 for item in [1, 2, 3, 4, 5]) The latter is the direct equivalent to `map()` (in Python 3).