Home > OS >  'NoneType' object is not subscriptable in list when expanding
'NoneType' object is not subscriptable in list when expanding

Time:09-19

Hi guys i need help im doin my personal project and i dont know how to move from this error and make the f...ing list subscriptable.

k = int(input("Počet políčok s pohyblivým pieskom: ")) *#This is basically input for down bellow thingy*

if k >= 1:
    for i in range(k):
        cords_p = []
        cords_p = cords_p.extend([int(element_c) for element_c in input("Poloha políčka: ").split()]) *# My main part of problem*
else:
    print(cords_p)


x = cords[0]
y = cords[1]
print(x," ",y)

#It continues dow bellow with some If statements

And basically why i need it to make it subcriptable, bc im creating a grid and this input above are cords of the points were you cant go and for that im down bellow using some if statements and logical operations and in input the user is inputing 2 numbers exp. (0 2) one for X-axis one for Y-axis for that one problem is that that code up without the cords.extend is rewriting my list and if its there the cords.extend i cannot use it in if statements bc its telling me its not subcriptable. For whole picture i need to create algorithm that will tell us whole path from start to end and take the smallest amount of steps in the proces and ditch the points were you cant go exp. of the if segment.

while cords[0] != cord_end[0] and cords[1] != cords_p[1]:
    while cords[1] != cord_end[1]:
        if cords[0] != cords_p[0]:
            if cords[0] <= cord_end[0] and cords[0] != cords_p[0]:
                cords[0] = cords[0] 1
                x = x 1
                print(x," ",y)
                continue
            elif cords[0] == cords_p[0] and cords[1] != cords_p[1]:
                cords[0] = cords[0] 1
                print(x," ",y)
                continue
        elif cords[1] == cords_p[1]:
            cords[0] = cords[0] 1
            print(x," ",y)
            continue
        break
    while cords[0] != cord_end[0]:   
        if cords[1] != cords_p[1]:        
            if cords[1] <= cord_end[1] and cords[1] != cords_p[1]:
                cords[1] = cords[1] 1
                y = y 1
                print(x," ",y)
                continue
            elif cords[1] == cords_p[1] and cords[0] != cords_p[0]:
                cords[1] = cords[1] 1
                print(x," ",y)
                continue
        elif cords[0] == cords_p[0]:
            cords[1] = cords[1] 1
            print(x," ",y)
            continue
        break     
print(cords)

So please help i will be very grateful. Good day to you all. Also for further explanation im not experienced programmer much at best im advanced beginner and know what some little advanced things do. (Not dumb just not experienced like experts here maybe bc im on high school just and could find any suitable experience)

CodePudding user response:

The extend function operates directly on the list (inplace) and returns nothing. So cords_p = cords_p.extend([int(element_c) for element_c in input("Poloha políčka: ").split()]) assigns None to cords_p. Just call the function without the assignment.

  • Related