Skip to content Skip to sidebar Skip to footer

Multiplying Some Elements Of A List By And Constant And Others By A Different Constant

I need to multiply first 3 elements of a list by a constant (say 0.3) and rest of the elements by a different constant (say 0.7). Input: A list of unspecified length. experience_yr

Solution 1:

Here's another way, using a list comprehension:

[ x*0.3 if i<3 else x*0.7   for i,x in enumerate(experience_yrs)  ]

Post a Comment for "Multiplying Some Elements Of A List By And Constant And Others By A Different Constant"