如何将列表中的某些数字相乘?例如:
if i >= 3:
result = [i* 3 for i in list]
if i < 3:
result = [i * 2 for i in list]
``
我已经尝试了以下功能,但没有成功:
def special_multiply(list, multiplicator,multiplicator_2):
for i in list:
if i >= 3:
result = [i* multiplicator for i in list]
if i < 3:
result = [i * multiplicator_2 for i in list]
return result
print("Special multiply:", special_multiply([1,2,3,4,5,6],2,3))
I expected following output:[2,4,9,12,15,18]
提前感谢!
1条答案
按热度按时间inn6fuwd1#
请尝试以下操作: