初学者。Python列表。整型字符串(&s)

2021-06-14 22:07:42 发布

您现在位置:Python中文网/ 问答频道 /正文

def changeList(myList):
    myList = myList[3:]
    new_list = []

    count = -1
    for line in myList:
        count += 1
        new_list += [list(myList[count])]

    count1 = -1
    for i in new_list:

         count1 += 1
         count2 = -1

         for j in i:

             count2 += 1

             if j == "-":
                 new_list[count1][count2] = 0 #- 0 - Can't go there.
             elif j == "|":
                 new_list[count1][count2] = 0 #| 0 - Can't go there.
             elif j == "+":
                 new_list[count1][count2] = 0 #+ 0 - Can't go there.
             elif j == " ":
                 new_list[count1][count2] = 1 #Blank - 1 for empty cell.

    for i in new_list:

       print(i)

    return new_list

为什么我这么做。。。你知道吗

print(type(new_list[0][0]))

它以字符串形式返回类型?我需要它是一个int,就像我指定的那样。当我打印出新的目录时。它不会将内容显示为[“0”,“0”,…等]而是将它们显示为[0,0,0…等]它们必须是整数。我错过了什么。谢谢。你知道吗

我在函数(myList)中输入的参数如下所示。。。你知道吗

['10 20', '1 1', '10 20', '-----------------------------------------', '|     |       | | |       |     | |     |', '|-+ +-+-+ + + + + + +-+ + + +-+-+ + + +-|'...etc

我想去

new_list[0][0] = 3

但它不会让我!?你知道吗