Python 2.7 如何仅对列表中的某个值应用函数?

Python 2.7 如何仅对列表中的某个值应用函数?,python-2.7,Python 2.7,所以我必须制作一个版本更新程序来更新版本号中的值。因此,对于11.3.4.5,我希望我的索引函数更新该列表中的一个数字,然后将所有剩余值更改为0。因此,如果我希望索引为0,它将更改列表的第一个值,因此新列表将为12.0.0.0。如果有人能告诉我如何设置它,那就太好了。到目前为止,我已经做到了这一点,但我还是被卡住了: def updateVersion(numbers, index): version = [] index = for i in numbers:

所以我必须制作一个版本更新程序来更新版本号中的值。因此,对于11.3.4.5,我希望我的索引函数更新该列表中的一个数字,然后将所有剩余值更改为0。因此,如果我希望索引为0,它将更改列表的第一个值,因此新列表将为12.0.0.0。如果有人能告诉我如何设置它,那就太好了。到目前为止,我已经做到了这一点,但我还是被卡住了:

def updateVersion(numbers, index): 
   version = []
   index = 
       for i in numbers:
          if any(version):
          i + 1
          return version

假设您提供一个列表作为参数:

def updateVersion(currVersion, index):
     if index == 0:
         return [currVersion[0] + 1] + [0] * (len(currVersion) - 1)
     else:
         return [currVersion[0], index] + [0] * (len(currVersion) - 2)

我不确定你的问题是否正确。但我会这样做:

current_version = [11,3,4,5] 

def updateVersion(version, index):

    i = 0
    new_version = [None] * len(version)#get length of the Version - number and create an empty list with the same length

    for number in version:
        if i == index: # increment the Version Number
            new_version[i] = version[i] + 1
        elif i > index: # All numbers after the increment are 0
            new_version[i] = 0
        else:
            new_version[i] = version[i]
        i = i + 1 

    return new_version

print str(updateVersion(current_version, 0))#just for testing
所以这里的输出是:

[12,0,0,0]