Python 只作用于嵌套列表中整数的函数?
有没有办法让我的函数只将速度列表中的整数乘以5,而忽略名称?您可以这样声明更新Python 只作用于嵌套列表中整数的函数?,python,Python,有没有办法让我的函数只将速度列表中的整数乘以5,而忽略名称?您可以这样声明更新 speed=[['Adam', 50], ['Bob', 25], ['Charlie', 10]] def update(lst1): nl=[] for i in lst1: nl.append(i*5) return nl 然后打电话 def update(lst1): for v in lst1: v[1] *= 5 使用列表理解 upda
speed=[['Adam', 50], ['Bob', 25], ['Charlie', 10]]
def update(lst1):
nl=[]
for i in lst1:
nl.append(i*5)
return nl
然后打电话
def update(lst1):
for v in lst1:
v[1] *= 5
使用列表理解
update(speed)
当然将数字相乘并忽略字符串?据推测,数字将始终位于
i[1]
,字符串将始终位于i[0]
?速度=[[name,num*5]表示(name,num)的速度]
nl = [ [x[0], x[1] * 5] for x in lst ]