Modify a large list without any loops in python
问题 My list is: a=[1,2,3,4] Now I want my list to be: a=[-1,-2,-3,-4] How can I change my list this way without using any loops? Update: this may be a large list, on the order of 10000 elements. 回答1: Use Python's map functionality a[:] = map(lambda x: -x, a) Here's the description of the map function from the above link: map(function, iterable, ...) Apply function to every item of iterable and return a list of the results. If additional iterable arguments are passed, function must take that many