在列表推导

时间:2017-05-11 04:21:11

标签: python-3.x

我正在学习列表理解,我想知道是否可以为子列表分配新值。

newConfig = ['0', '0']

original = open("ciscoconf.txt", "r")

originalList = original.read().split("!") 

originalLen = len(originalLen) - 1 

for i in range(1, originalLen):
    originalList[i] = originalList[i].split("\n")

newConfig[0] = input(str("New IP"))

for i in range(originalLen):
    q = 0
    for k in originalList[i]:

        if k.find('ip address') == 0:
            originalList[i][q] = "ip address " + " ".join(newConfig)

        q += 1

0 个答案:

没有答案