Am 27.05.19 um 06:12 schrieb Cameron Simpson: > On 26May2019 21:52, Montana Burr <[email protected]> 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). _______________________________________________ Python-ideas mailing list [email protected] https://mail.python.org/mailman/listinfo/python-ideas Code of Conduct: http://python.org/psf/codeofconduct/
