pythonlist

Doing math to a list in python


How do I, say, take [111, 222, 333] and multiply it by 3 to get [333, 666, 999]?


See also: How can I collect the results of a repeated calculation in a list, dictionary etc. (or make a copy of a list with each element modified)? . However, some techniques - especially ones involving Numpy - are specific to "doing math".


Solution

  • [3*x for x in [111, 222, 333]]