bharath bharath - 1 year ago 122
Python Question

In Python how will you multiply individual elements of a list with a floating point or integer number?

S=[22 33 45.6 21.6 51.8]

Here S is an array

How will I multiply this and get the value?

SP=[53.9 80.85 111.72 52.92 126.91]

Answer Source

You can use built-in map function:

result = map(lambda x: x * P, S)

or list comprehensions that is a bit more pythonic:

result = [x * P for x in S]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download